@aeriajs/core 0.0.115 → 0.0.117

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/assets.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { Context, Collection, Token } from '@aeriajs/types';
1
+ import type { AssetType, Context, Collection, Token } from '@aeriajs/types';
2
2
  import { ACError } from '@aeriajs/types';
3
- export declare const internalGetCollectionAsset: <TCollectionName extends string, TAssetName extends "item" | "description" | "security" | "functions" | "contracts" | "exposedFunctions">(collectionName: TCollectionName, assetName: TAssetName) => Promise<{
3
+ export declare const internalGetCollectionAsset: <TCollectionName extends string, TAssetName extends keyof Collections[TCollectionName] & AssetType>(collectionName: TCollectionName, assetName: TAssetName) => Promise<{
4
4
  readonly _tag: "Error";
5
5
  readonly error: ACError.ResourceNotFound;
6
6
  readonly result: undefined;
@@ -9,7 +9,7 @@ export declare const internalGetCollectionAsset: <TCollectionName extends string
9
9
  readonly error: undefined;
10
10
  readonly result: NonNullable<Collection[TAssetName]>;
11
11
  }>;
12
- export declare const getCollectionAsset: <TCollectionName extends string, TAssetName extends "item" | "description" | "security" | "functions" | "contracts" | "exposedFunctions">(collectionName: TCollectionName, assetName: TAssetName) => Promise<{
12
+ export declare const getCollectionAsset: <TCollectionName extends string, TAssetName extends keyof Collections[TCollectionName] & AssetType>(collectionName: TCollectionName, assetName: TAssetName) => Promise<{
13
13
  readonly _tag: "Error";
14
14
  readonly error: ACError.ResourceNotFound;
15
15
  readonly result: undefined;
@@ -2,7 +2,7 @@ import type { SchemaWithId, Collection, StrictContext, Contract, ContractToFunct
2
2
  export type ExtendCollection<TLeftCollection extends Collection, TRightCollection> = Omit<TLeftCollection & TRightCollection, 'item'> & {
3
3
  item: SchemaWithId<(TLeftCollection & TRightCollection)['description']>;
4
4
  };
5
- export declare const defineCollection: <TCollection extends Omit<Collection<TCollection extends Collection ? TCollection : never>, "item" | "description" | "security" | "functions" | "exposedFunctions">, const TDescription extends Description<TDescription>, const TContracts extends { [P in keyof TFunctions]?: Contract | undefined; }, const TExposedFunctions extends Partial<Record<keyof TFunctions, AccessCondition>>, const TFunctions extends Record<string, (payload: any, context: StrictContext<any>) => any> & { [P_1 in keyof TContracts | keyof TExposedFunctions]: ContractToFunction<P_1 extends keyof TContracts ? NonNullable<TContracts[P_1]> : any, StrictContext<P_1 extends keyof TExposedFunctions ? RoleFromAccessCondition<TExposedFunctions[P_1]> : never, TDescription>>; }>(collection: TCollection & {
5
+ export declare const defineCollection: <TCollection extends Collection<TCollection extends Collection ? TCollection : never> extends infer Coll ? Omit<Coll, "item" | "description" | "functions" | "exposedFunctions" | "security"> : never, const TDescription extends Description<TDescription>, const TContracts extends { [P in keyof TFunctions]?: Contract; }, const TExposedFunctions extends Partial<Record<keyof TFunctions, AccessCondition>>, const TFunctions extends Record<string, (payload: any, context: StrictContext<any>) => any> & { [P in keyof TContracts | keyof TExposedFunctions]: ContractToFunction<P extends keyof TContracts ? NonNullable<TContracts[P]> : any, StrictContext<P extends keyof TExposedFunctions ? RoleFromAccessCondition<TExposedFunctions[P]> : never, TDescription>>; }>(collection: TCollection & {
6
6
  description: TDescription;
7
7
  functions?: TFunctions;
8
8
  contracts?: TContracts;
@@ -16,11 +16,4 @@ export declare const defineCollection: <TCollection extends Omit<Collection<TCol
16
16
  functions: TFunctions;
17
17
  contracts: TContracts;
18
18
  };
19
- export declare const extendCollection: <const TLeftCollection extends Collection, const TRightCollection extends {
20
- description?: Partial<Description> | undefined;
21
- item?: Partial<any> | undefined;
22
- security?: Partial<CollectionSecurityPolicy<any> | undefined>;
23
- functions?: Partial<Record<string, (payload: any, context: import("@aeriajs/types").Context<any>, ...args: any[]) => any> | undefined>;
24
- contracts?: Partial<Record<string, Contract> | undefined>;
25
- exposedFunctions?: Partial<Record<string, AccessCondition> | undefined>;
26
- }>(left: TLeftCollection, right: TRightCollection) => ExtendCollection<TLeftCollection, TRightCollection>;
19
+ export declare const extendCollection: <const TLeftCollection extends Collection, const TRightCollection extends { [P in keyof Collection]?: Partial<Collection[P]>; }>(left: TLeftCollection, right: TRightCollection) => ExtendCollection<TLeftCollection, TRightCollection>;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { Description, Property } from '@aeriajs/types';
3
2
  import * as presets from '../presets/index.js';
4
3
  export type PreloadOptions = {
@@ -6,7 +5,7 @@ export type PreloadOptions = {
6
5
  memoize?: boolean;
7
6
  timestamps?: boolean;
8
7
  };
9
- export declare const applyPreset: (entry: Partial<Description> | Description['properties'], presetName: keyof typeof presets, parentName?: string) => (Record<string, Property> | Partial<Description>) & ({
8
+ export declare const applyPreset: (entry: Partial<Description> | Description["properties"], presetName: keyof typeof presets, parentName?: string) => (Record<string, Property> | Partial<Description>) & ({
10
9
  readonly actions: {
11
10
  readonly removeAll: {
12
11
  readonly label: "action.removeAll";
@@ -19,6 +19,6 @@ export type BuildLookupOptions = {
19
19
  memoize?: string;
20
20
  project?: string[];
21
21
  };
22
- export declare const getReferences: (properties: FixedObjectProperty['properties'], options?: GetReferenceOptions) => Promise<{}>;
22
+ export declare const getReferences: (properties: FixedObjectProperty["properties"], options?: GetReferenceOptions) => Promise<{}>;
23
23
  export declare const buildLookupPipeline: (referenceMap: ReferenceMap | {}, options: BuildLookupOptions) => Promise<any[]>;
24
- export declare const getLookupPipeline: (description: Description, _options?: Omit<BuildLookupOptions, 'properties'>) => Promise<any[]>;
24
+ export declare const getLookupPipeline: (description: Description, _options?: Omit<BuildLookupOptions, "properties">) => Promise<any[]>;
@@ -269,41 +269,48 @@ const recurse = async (target, ctx) => {
269
269
  ]);
270
270
  continue;
271
271
  }
272
- if (!property && value && (value.constructor === Object || value.constructor === Array)) {
273
- // if first propName is preceded by '$' we assume
274
- // it contains MongoDB query operators
275
- if (Object.keys(value)[0]?.startsWith('$')) {
276
- if (!ctx.options.allowOperators) {
277
- return types_1.Result.error(types_1.ACError.InsecureOperator);
272
+ if (!property) {
273
+ if (value && (value.constructor === Object || value.constructor === Array)) {
274
+ // if first propName is preceded by '$' we assume
275
+ // it contains MongoDB query operators
276
+ if (Object.keys(value)[0]?.startsWith('$')) {
277
+ if (!ctx.options.allowOperators) {
278
+ return types_1.Result.error(types_1.ACError.InsecureOperator);
279
+ }
280
+ entries.push([
281
+ propName,
282
+ value,
283
+ ]);
284
+ continue;
278
285
  }
279
- entries.push([
280
- propName,
281
- value,
282
- ]);
283
- continue;
284
- }
285
- if (Array.isArray(value)) {
286
- const operations = [];
287
- for (const operation of value) {
288
- const { error, result } = await recurse(operation, ctx);
289
- if (error) {
290
- return types_1.Result.error(error);
286
+ if (Array.isArray(value)) {
287
+ const operations = [];
288
+ for (const operation of value) {
289
+ const { error, result } = await recurse(operation, ctx);
290
+ if (error) {
291
+ return types_1.Result.error(error);
292
+ }
293
+ operations.push(result);
291
294
  }
292
- operations.push(result);
295
+ entries.push([
296
+ propName,
297
+ operations,
298
+ ]);
299
+ continue;
300
+ }
301
+ const { error, result: operator } = await recurse(value, ctx);
302
+ if (error) {
303
+ return types_1.Result.error(error);
293
304
  }
294
305
  entries.push([
295
306
  propName,
296
- operations,
307
+ operator,
297
308
  ]);
298
309
  continue;
299
310
  }
300
- const { error, result: operator } = await recurse(value, ctx);
301
- if (error) {
302
- return types_1.Result.error(error);
303
- }
304
311
  entries.push([
305
312
  propName,
306
- operator,
313
+ value,
307
314
  ]);
308
315
  }
309
316
  if (property) {
@@ -233,39 +233,46 @@ const recurse = async (target, ctx) => {
233
233
  ]);
234
234
  continue;
235
235
  }
236
- if (!property && value && (value.constructor === Object || value.constructor === Array)) {
237
- if (Object.keys(value)[0]?.startsWith("$")) {
238
- if (!ctx.options.allowOperators) {
239
- return Result.error(ACError.InsecureOperator);
236
+ if (!property) {
237
+ if (value && (value.constructor === Object || value.constructor === Array)) {
238
+ if (Object.keys(value)[0]?.startsWith("$")) {
239
+ if (!ctx.options.allowOperators) {
240
+ return Result.error(ACError.InsecureOperator);
241
+ }
242
+ entries.push([
243
+ propName,
244
+ value
245
+ ]);
246
+ continue;
240
247
  }
241
- entries.push([
242
- propName,
243
- value
244
- ]);
245
- continue;
246
- }
247
- if (Array.isArray(value)) {
248
- const operations = [];
249
- for (const operation of value) {
250
- const { error: error2, result } = await recurse(operation, ctx);
251
- if (error2) {
252
- return Result.error(error2);
248
+ if (Array.isArray(value)) {
249
+ const operations = [];
250
+ for (const operation of value) {
251
+ const { error: error2, result } = await recurse(operation, ctx);
252
+ if (error2) {
253
+ return Result.error(error2);
254
+ }
255
+ operations.push(result);
253
256
  }
254
- operations.push(result);
257
+ entries.push([
258
+ propName,
259
+ operations
260
+ ]);
261
+ continue;
262
+ }
263
+ const { error, result: operator } = await recurse(value, ctx);
264
+ if (error) {
265
+ return Result.error(error);
255
266
  }
256
267
  entries.push([
257
268
  propName,
258
- operations
269
+ operator
259
270
  ]);
260
271
  continue;
261
272
  }
262
- const { error, result: operator } = await recurse(value, ctx);
263
- if (error) {
264
- return Result.error(error);
265
- }
266
273
  entries.push([
267
274
  propName,
268
- operator
275
+ value
269
276
  ]);
270
277
  }
271
278
  if (property) {
@@ -3,7 +3,7 @@ import { MongoClient } from 'mongodb';
3
3
  export { ObjectId, } from 'mongodb';
4
4
  export declare const getDatabase: () => Promise<{
5
5
  client: MongoClient;
6
- db: ReturnType<MongoClient['db']> | undefined;
6
+ db: ReturnType<MongoClient["db"]> | undefined;
7
7
  }>;
8
8
  export declare const getDatabaseSync: () => import("mongodb").Db;
9
9
  export declare const prepareCollectionName: (collectionName: string) => string;
@@ -1,5 +1,5 @@
1
1
  import type { Context, SchemaWithId, CountPayload } from '@aeriajs/types';
2
- export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<Context['description']>>, context: TContext extends Context<any> ? TContext : never) => Promise<{
2
+ export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context<any> ? TContext : never) => Promise<{
3
3
  readonly _tag: "Result";
4
4
  readonly error: undefined;
5
5
  readonly result: any;
@@ -2,4 +2,4 @@ import type { Context, SchemaWithId, GetPayload, GetReturnType } from '@aeriajs/
2
2
  export type GetOptions = {
3
3
  bypassSecurity?: boolean;
4
4
  };
5
- export declare const get: <TContext extends Context>(payload: GetPayload<SchemaWithId<TContext['description']>>, context: TContext extends Context<any> ? TContext : never, options?: GetOptions) => Promise<GetReturnType<TContext['description']>>;
5
+ export declare const get: <TContext extends Context>(payload: GetPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context<any> ? TContext : never, options?: GetOptions) => Promise<GetReturnType<TContext["description"]>>;
@@ -2,7 +2,7 @@ import type { Context, SchemaWithId, GetAllPayload } from '@aeriajs/types';
2
2
  export type GetAllOptions = {
3
3
  bypassSecurity?: boolean;
4
4
  };
5
- export declare const getAll: <TContext extends Context>(_payload: GetAllPayload<SchemaWithId<Context['description']>> | undefined, context: TContext, options?: GetAllOptions) => Promise<{
5
+ export declare const getAll: <TContext extends Context>(_payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<{
6
6
  readonly _tag: "Result";
7
7
  readonly error: undefined;
8
8
  readonly result: SchemaWithId<TContext["description"]>[];
@@ -33,4 +33,4 @@ export declare const insertErrorSchema: () => {
33
33
  };
34
34
  };
35
35
  };
36
- export declare const insert: <TContext extends Context>(payload: InsertPayload<SchemaWithId<TContext['description']>>, context: TContext, options?: InsertOptions) => Promise<InsertReturnType<SchemaWithId<TContext['description']>>>;
36
+ export declare const insert: <TContext extends Context>(payload: InsertPayload<SchemaWithId<TContext["description"]>>, context: TContext, options?: InsertOptions) => Promise<InsertReturnType<SchemaWithId<TContext["description"]>>>;
@@ -1,6 +1,6 @@
1
1
  import type { Context, SchemaWithId, RemovePayload } from '@aeriajs/types';
2
2
  import { Result, HTTPStatus, ACError } from '@aeriajs/types';
3
- export declare const remove: <TContext extends Context>(payload: RemovePayload<SchemaWithId<TContext['description']>>, context: TContext) => Promise<Result.Error<{
3
+ export declare const remove: <TContext extends Context>(payload: RemovePayload<SchemaWithId<TContext["description"]>>, context: TContext) => Promise<Result.Error<{
4
4
  readonly code: ACError.ResourceNotFound;
5
5
  } & {
6
6
  httpStatus: HTTPStatus.NotFound;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.115",
3
+ "version": "0.0.117",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -41,11 +41,11 @@
41
41
  "mongodb-memory-server": "^9.2.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@aeriajs/builtins": "^0.0.115",
44
+ "@aeriajs/builtins": "^0.0.117",
45
45
  "@aeriajs/common": "^0.0.74",
46
46
  "@aeriajs/entrypoint": "^0.0.76",
47
47
  "@aeriajs/http": "^0.0.85",
48
- "@aeriajs/security": "^0.0.115",
48
+ "@aeriajs/security": "^0.0.117",
49
49
  "@aeriajs/types": "^0.0.64",
50
50
  "@aeriajs/validation": "^0.0.77"
51
51
  },