Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions packages/oc-azure-sql-metadata-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import sql from 'mssql';
import {
type ComponentRow,
type MetadataStatus,
type MetadataStore,
type MetadataStoreWithCallbacks,
VERSION_ALREADY_EXISTS,
VERSION_PUBLISH_IN_PROGRESS,
type VersionAlreadyExistsError
type VersionAlreadyExistsError,
withCallbacks
} from 'oc-metadata-adapters-utils';

export type { ComponentRow, MetadataStore } from 'oc-metadata-adapters-utils';
Expand Down Expand Up @@ -189,7 +190,7 @@ const addComponentRowInputs = (

export default function azureSqlMetadataAdapter(
options?: AzureSqlMetadataAdapterOptions
): MetadataStore {
): MetadataStoreWithCallbacks {
const adapterType = 'azure-sql';
const metadataOptions = options || ({} as AzureSqlMetadataAdapterOptions);
const manageSchema = metadataOptions.manageSchema !== false;
Expand Down Expand Up @@ -315,7 +316,8 @@ export default function azureSqlMetadataAdapter(
`);
};

return {
const adapter = {
adapterApi: 'promise' as const,
adapterType,

isValid(): boolean {
Expand Down Expand Up @@ -485,4 +487,37 @@ export default function azureSqlMetadataAdapter(
}
}
};

return {
...adapter,
initialise: withCallbacks(
adapter.initialise,
'oc-azure-sql-metadata-adapter'
),
getAllComponents: withCallbacks(
adapter.getAllComponents,
'oc-azure-sql-metadata-adapter'
),
addVersion: withCallbacks(
adapter.addVersion,
'oc-azure-sql-metadata-adapter'
),
reserveVersion: withCallbacks(
adapter.reserveVersion,
'oc-azure-sql-metadata-adapter'
),
commitVersion: withCallbacks(
adapter.commitVersion,
'oc-azure-sql-metadata-adapter'
),
abortVersion: withCallbacks(
adapter.abortVersion,
'oc-azure-sql-metadata-adapter'
),
getChangeToken: withCallbacks(
adapter.getChangeToken,
'oc-azure-sql-metadata-adapter'
),
close: withCallbacks(adapter.close, 'oc-azure-sql-metadata-adapter')
} as MetadataStoreWithCallbacks;
}
11 changes: 11 additions & 0 deletions packages/oc-azure-sql-metadata-adapter/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ describe('oc-azure-sql-metadata-adapter', () => {
});
});

it('should support the legacy callback form', (done) => {
const { adapter } = createAdapter();
const store = adapter({ server: 'localhost', database: 'oc' });

store.getAllComponents((error, rows) => {
expect(error).to.equal(null);
expect(rows).to.eql([]);
done();
});
});

describe('initialise()', () => {
it('should create the schema by default', async () => {
const { adapter, pools, queryStub } = createAdapter();
Expand Down
52 changes: 40 additions & 12 deletions packages/oc-azure-storage-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import Cache from 'nice-cache';
import nodeDir, { type PathsResult } from 'node-dir';
import {
getFileInfo,
type StorageAdapter,
type StorageAdapterBaseConfig,
strings
type StorageAdapterWithCallbacks,
strings,
withCallbacks
} from 'oc-storage-adapters-utils';

const getPaths: (path: string) => Promise<PathsResult> = promisify(
Expand Down Expand Up @@ -66,7 +67,9 @@ export interface AzureConfig extends StorageAdapterBaseConfig {
| TokenCredential;
}

export default function azureAdapter(conf: AzureConfig): StorageAdapter {
export default function azureAdapter(
conf: AzureConfig
): StorageAdapterWithCallbacks {
const isValid = () => {
if (
!conf.publicContainerName ||
Expand Down Expand Up @@ -291,19 +294,44 @@ export default function azureAdapter(conf: AzureConfig): StorageAdapter {
};

return {
getFile,
getJson,
adapterApi: 'promise',
getFile: withCallbacks(
getFile,
'oc-azure-storage-adapter'
) as StorageAdapterWithCallbacks['getFile'],
getJson: withCallbacks(
getJson,
'oc-azure-storage-adapter'
) as StorageAdapterWithCallbacks['getJson'],
getUrl,
listSubDirectories,
listSubDirectories: withCallbacks(
listSubDirectories,
'oc-azure-storage-adapter'
) as StorageAdapterWithCallbacks['listSubDirectories'],
maxConcurrentRequests: 20,
putDir,
putFile,
putFileContent,
removeFile,
removeDir,
putDir: withCallbacks(
putDir,
'oc-azure-storage-adapter'
) as StorageAdapterWithCallbacks['putDir'],
putFile: withCallbacks(
putFile,
'oc-azure-storage-adapter'
) as StorageAdapterWithCallbacks['putFile'],
putFileContent: withCallbacks(
putFileContent,
'oc-azure-storage-adapter'
) as StorageAdapterWithCallbacks['putFileContent'],
removeFile: withCallbacks(
removeFile,
'oc-azure-storage-adapter'
) as StorageAdapterWithCallbacks['removeFile'],
removeDir: withCallbacks(
removeDir,
'oc-azure-storage-adapter'
) as StorageAdapterWithCallbacks['removeDir'],
adapterType: 'azure-blob-storage',
isValid
};
} as StorageAdapterWithCallbacks;
}

module.exports = azureAdapter;
12 changes: 11 additions & 1 deletion packages/oc-azure-storage-adapter/test/azure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ test('should expose the correct methods', () => {
});
});

test('should support the legacy callback form', (done) => {
const client = azure(validOptions);

client.getFile('path/test.txt', (error, value) => {
expect(error).toBeNull();
expect(value).toBe('Hello!');
done();
});
});

test('validate valid conf without credentials', () => {
const options = {
accountName: 'name',
Expand Down Expand Up @@ -119,7 +129,7 @@ test('validate missing name', () => {
test(`test getFile ${scenario.src}`, async () => {
const client = azure(validOptions);
const operation = () =>
client[scenario.src.match(/\.json$/) ? 'getJson' : 'getFile'](
(client as any)[scenario.src.match(/\.json$/) ? 'getJson' : 'getFile'](
scenario.src,
false
);
Expand Down
43 changes: 39 additions & 4 deletions packages/oc-azure-table-metadata-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
import { DefaultAzureCredential, type TokenCredential } from '@azure/identity';
import {
type ComponentRow,
type MetadataStore,
type MetadataStoreWithCallbacks,
VERSION_ALREADY_EXISTS,
VERSION_PUBLISH_IN_PROGRESS,
type VersionAlreadyExistsError
type VersionAlreadyExistsError,
withCallbacks
} from 'oc-metadata-adapters-utils';

export type { ComponentRow, MetadataStore } from 'oc-metadata-adapters-utils';
Expand Down Expand Up @@ -159,7 +160,7 @@ const getComponentEntity = (

export default function azureTableMetadataAdapter(
options?: AzureTableMetadataAdapterOptions
): MetadataStore {
): MetadataStoreWithCallbacks {
const adapterType = 'azure-table';
const opts = options || ({} as AzureTableMetadataAdapterOptions);
const manageSchema = opts.manageSchema !== false;
Expand Down Expand Up @@ -332,7 +333,8 @@ export default function azureTableMetadataAdapter(
}
};

return {
const adapter = {
adapterApi: 'promise' as const,
adapterType,

isValid(): boolean {
Expand Down Expand Up @@ -518,4 +520,37 @@ export default function azureTableMetadataAdapter(
client = undefined;
}
};

return {
...adapter,
initialise: withCallbacks(
adapter.initialise,
'oc-azure-table-metadata-adapter'
),
getAllComponents: withCallbacks(
adapter.getAllComponents,
'oc-azure-table-metadata-adapter'
),
addVersion: withCallbacks(
adapter.addVersion,
'oc-azure-table-metadata-adapter'
),
reserveVersion: withCallbacks(
adapter.reserveVersion,
'oc-azure-table-metadata-adapter'
),
commitVersion: withCallbacks(
adapter.commitVersion,
'oc-azure-table-metadata-adapter'
),
abortVersion: withCallbacks(
adapter.abortVersion,
'oc-azure-table-metadata-adapter'
),
getChangeToken: withCallbacks(
adapter.getChangeToken,
'oc-azure-table-metadata-adapter'
),
close: withCallbacks(adapter.close, 'oc-azure-table-metadata-adapter')
} as MetadataStoreWithCallbacks;
}
15 changes: 15 additions & 0 deletions packages/oc-azure-table-metadata-adapter/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ describe('oc-azure-table-metadata-adapter', () => {
});
});

it('should support the legacy callback form', (done) => {
const { adapter } = createAdapter({
listEntities: sinon.stub().returns({
async *[Symbol.asyncIterator]() {}
})
});
const store = adapter({ connectionString: 'foo' });

store.getAllComponents((error, rows) => {
expect(error).to.equal(null);
expect(rows).to.eql([]);
done();
});
});

describe('initialise()', () => {
it('should create the table by default', async () => {
const { adapter, createTableStub } = createAdapter();
Expand Down
50 changes: 38 additions & 12 deletions packages/oc-gs-storage-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import Cache from 'nice-cache';
import nodeDir, { type PathsResult } from 'node-dir';
import {
getFileInfo,
type StorageAdapter,
type StorageAdapterBaseConfig,
strings
type StorageAdapterWithCallbacks,
strings,
withCallbacks
} from 'oc-storage-adapters-utils';
import tmp from 'tmp';

Expand All @@ -32,7 +33,7 @@ export interface GsConfig extends StorageAdapterBaseConfig {
maxAge?: boolean;
}

export default function gsAdapter(conf: GsConfig): StorageAdapter {
export default function gsAdapter(conf: GsConfig): StorageAdapterWithCallbacks {
const isValid = () => {
if (!conf.bucket || !conf.projectId || !conf.path) {
return false;
Expand Down Expand Up @@ -332,19 +333,44 @@ export default function gsAdapter(conf: GsConfig): StorageAdapter {
};

return {
getFile,
getJson,
adapterApi: 'promise',
getFile: withCallbacks(
getFile,
'oc-gs-storage-adapter'
) as StorageAdapterWithCallbacks['getFile'],
getJson: withCallbacks(
getJson,
'oc-gs-storage-adapter'
) as StorageAdapterWithCallbacks['getJson'],
getUrl,
listSubDirectories,
listSubDirectories: withCallbacks(
listSubDirectories,
'oc-gs-storage-adapter'
) as StorageAdapterWithCallbacks['listSubDirectories'],
maxConcurrentRequests: 20,
putDir,
putFile,
putFileContent,
removeDir,
removeFile,
putDir: withCallbacks(
putDir,
'oc-gs-storage-adapter'
) as StorageAdapterWithCallbacks['putDir'],
putFile: withCallbacks(
putFile,
'oc-gs-storage-adapter'
) as StorageAdapterWithCallbacks['putFile'],
putFileContent: withCallbacks(
putFileContent,
'oc-gs-storage-adapter'
) as StorageAdapterWithCallbacks['putFileContent'],
removeDir: withCallbacks(
removeDir,
'oc-gs-storage-adapter'
) as StorageAdapterWithCallbacks['removeDir'],
removeFile: withCallbacks(
removeFile,
'oc-gs-storage-adapter'
) as StorageAdapterWithCallbacks['removeFile'],
adapterType: 'gs',
isValid
};
} as StorageAdapterWithCallbacks;
}

module.exports = gsAdapter;
12 changes: 11 additions & 1 deletion packages/oc-gs-storage-adapter/test/gs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ test('should expose the correct methods', () => {
});
});

test('should support the legacy callback form', (done) => {
const client = gs(validOptions);

client.getFile('path/test.txt', (error, value) => {
expect(error).toBeNull();
expect(value).toBe('Hello!');
done();
});
});

test('validate valid conf', () => {
const client = gs(validOptions);
expect(client.isValid()).toBe(true);
Expand Down Expand Up @@ -118,7 +128,7 @@ test('validate missing path conf', () => {
test(`test getFile ${scenario.src}`, async () => {
const client = gs(validOptions);
const operation = () =>
client[scenario.src.match(/\.json$/) ? 'getJson' : 'getFile'](
(client as any)[scenario.src.match(/\.json$/) ? 'getJson' : 'getFile'](
scenario.src,
false
);
Expand Down
Loading
Loading