@aeriajs/core 0.0.277 → 0.0.278

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.
Files changed (73) hide show
  1. package/dist/__scripts__/postinstall.js +2 -37
  2. package/dist/accessControl.js +14 -18
  3. package/dist/assets.js +25 -31
  4. package/dist/collection/cascadingRemove.js +14 -19
  5. package/dist/collection/define.js +5 -10
  6. package/dist/collection/description.js +2 -7
  7. package/dist/collection/index.js +8 -24
  8. package/dist/collection/makePagination.js +5 -9
  9. package/dist/collection/normalizeProjection.js +1 -5
  10. package/dist/collection/preload.js +13 -18
  11. package/dist/collection/reference.js +19 -26
  12. package/dist/collection/traverseDocument.js +90 -127
  13. package/dist/context.js +16 -53
  14. package/dist/database.js +12 -52
  15. package/dist/endpoints.js +11 -48
  16. package/dist/functions/count.js +11 -15
  17. package/dist/functions/get.js +20 -24
  18. package/dist/functions/getAll.js +8 -12
  19. package/dist/functions/index.js +9 -27
  20. package/dist/functions/insert.js +19 -23
  21. package/dist/functions/remove.js +15 -19
  22. package/dist/functions/removeAll.js +11 -15
  23. package/dist/functions/removeFile.js +7 -11
  24. package/dist/functions/unpaginatedGetAll.js +15 -19
  25. package/dist/functions/upload.js +19 -57
  26. package/dist/index.js +11 -51
  27. package/dist/presets/add.js +1 -4
  28. package/dist/presets/crud.js +1 -4
  29. package/dist/presets/duplicate.js +1 -4
  30. package/dist/presets/index.js +17 -20
  31. package/dist/presets/owned.js +1 -4
  32. package/dist/presets/remove.js +1 -4
  33. package/dist/presets/removeAll.js +1 -4
  34. package/dist/presets/timestamped.js +1 -4
  35. package/dist/presets/view.js +1 -4
  36. package/dist/token.js +7 -15
  37. package/package.json +12 -17
  38. package/dist/__scripts__/postinstall.mjs +0 -50
  39. package/dist/accessControl.mjs +0 -31
  40. package/dist/assets.mjs +0 -67
  41. package/dist/collection/cascadingRemove.mjs +0 -71
  42. package/dist/collection/define.mjs +0 -13
  43. package/dist/collection/description.mjs +0 -8
  44. package/dist/collection/index.mjs +0 -9
  45. package/dist/collection/makePagination.mjs +0 -20
  46. package/dist/collection/normalizeProjection.mjs +0 -17
  47. package/dist/collection/preload.mjs +0 -88
  48. package/dist/collection/reference.mjs +0 -374
  49. package/dist/collection/traverseDocument.mjs +0 -454
  50. package/dist/context.mjs +0 -120
  51. package/dist/database.mjs +0 -49
  52. package/dist/endpoints.mjs +0 -52
  53. package/dist/functions/count.mjs +0 -50
  54. package/dist/functions/get.mjs +0 -89
  55. package/dist/functions/getAll.mjs +0 -14
  56. package/dist/functions/index.mjs +0 -12
  57. package/dist/functions/insert.mjs +0 -102
  58. package/dist/functions/remove.mjs +0 -41
  59. package/dist/functions/removeAll.mjs +0 -40
  60. package/dist/functions/removeFile.mjs +0 -29
  61. package/dist/functions/unpaginatedGetAll.mjs +0 -123
  62. package/dist/functions/upload.mjs +0 -91
  63. package/dist/index.mjs +0 -14
  64. package/dist/presets/add.mjs +0 -12
  65. package/dist/presets/crud.mjs +0 -35
  66. package/dist/presets/duplicate.mjs +0 -11
  67. package/dist/presets/index.mjs +0 -19
  68. package/dist/presets/owned.mjs +0 -9
  69. package/dist/presets/remove.mjs +0 -11
  70. package/dist/presets/removeAll.mjs +0 -11
  71. package/dist/presets/timestamped.mjs +0 -19
  72. package/dist/presets/view.mjs +0 -14
  73. package/dist/token.mjs +0 -31
@@ -1,40 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- const path = __importStar(require("node:path"));
37
- const fs = __importStar(require("node:fs"));
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs';
38
3
  const DTS_FILENAME = 'aeria.d.ts';
39
4
  const makeDts = (typesPath) => `// this file will be overwritten
40
5
  import type {} from '@aeriajs/types'
@@ -1,36 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isFunctionExposed = exports.FunctionExposedStatus = void 0;
4
- const entrypoint_1 = require("@aeriajs/entrypoint");
5
- const common_1 = require("@aeriajs/common");
6
- exports.FunctionExposedStatus = {
1
+ import { getConfig } from '@aeriajs/entrypoint';
2
+ import { isGranted } from '@aeriajs/common';
3
+ export const FunctionExposedStatus = {
7
4
  FunctionNotExposed: 'FUNCTION_NOT_EXPOSED',
8
5
  FunctionNotGranted: 'FUNCTION_NOT_GRANTED',
9
6
  FunctionAccessible: 'FUNCTION_ACCESSIBLE',
10
7
  };
11
- const isFunctionExposed = async (collection, fnName, token) => {
12
- const config = await (0, entrypoint_1.getConfig)();
8
+ export const isFunctionExposed = async (collection, fnName, token) => {
9
+ const config = await getConfig();
13
10
  if (!collection.functions) {
14
- return exports.FunctionExposedStatus.FunctionNotExposed;
11
+ return FunctionExposedStatus.FunctionNotExposed;
15
12
  }
16
13
  if (collection.exposedFunctions && fnName in collection.exposedFunctions) {
17
14
  const exposed = collection.exposedFunctions[fnName];
18
15
  if (exposed === false) {
19
- return exports.FunctionExposedStatus.FunctionNotExposed;
16
+ return FunctionExposedStatus.FunctionNotExposed;
20
17
  }
21
18
  if (!token) {
22
- return exports.FunctionExposedStatus.FunctionAccessible;
19
+ return FunctionExposedStatus.FunctionAccessible;
23
20
  }
24
- return (0, common_1.isGranted)(exposed, token)
25
- ? exports.FunctionExposedStatus.FunctionAccessible
26
- : exports.FunctionExposedStatus.FunctionNotGranted;
21
+ return isGranted(exposed, token)
22
+ ? FunctionExposedStatus.FunctionAccessible
23
+ : FunctionExposedStatus.FunctionNotGranted;
27
24
  }
28
25
  if (config.security.exposeFunctionsByDefault) {
29
26
  if (config.security.exposeFunctionsByDefault !== 'unauthenticated' && (!token || !token.authenticated)) {
30
- return exports.FunctionExposedStatus.FunctionNotGranted;
27
+ return FunctionExposedStatus.FunctionNotGranted;
31
28
  }
32
- return exports.FunctionExposedStatus.FunctionAccessible;
29
+ return FunctionExposedStatus.FunctionAccessible;
33
30
  }
34
- return exports.FunctionExposedStatus.FunctionNotExposed;
31
+ return FunctionExposedStatus.FunctionNotExposed;
35
32
  };
36
- exports.isFunctionExposed = isFunctionExposed;
package/dist/assets.js CHANGED
@@ -1,70 +1,64 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFunction = exports.getCollectionAsset = exports.internalGetCollectionAsset = void 0;
4
- const types_1 = require("@aeriajs/types");
5
- const security_1 = require("@aeriajs/security");
6
- const entrypoint_1 = require("@aeriajs/entrypoint");
7
- const accessControl_js_1 = require("./accessControl.js");
1
+ import { Result, ACError } from '@aeriajs/types';
2
+ import { limitRate } from '@aeriajs/security';
3
+ import { getCollection } from '@aeriajs/entrypoint';
4
+ import { isFunctionExposed, FunctionExposedStatus } from './accessControl.js';
8
5
  const assetsMemo = {
9
6
  assets: {},
10
7
  };
11
- const internalGetCollectionAsset = async (collectionName, assetName) => {
12
- const collection = await (0, entrypoint_1.getCollection)(collectionName);
8
+ export const internalGetCollectionAsset = async (collectionName, assetName) => {
9
+ const collection = await getCollection(collectionName);
13
10
  const asset = collection?.[assetName];
14
11
  if (!asset) {
15
- return types_1.Result.error(types_1.ACError.ResourceNotFound);
12
+ return Result.error(ACError.ResourceNotFound);
16
13
  }
17
- return types_1.Result.result(asset);
14
+ return Result.result(asset);
18
15
  };
19
- exports.internalGetCollectionAsset = internalGetCollectionAsset;
20
- const getCollectionAsset = async (collectionName, assetName) => {
16
+ export const getCollectionAsset = async (collectionName, assetName) => {
21
17
  const cached = assetsMemo.assets[collectionName];
22
18
  if (cached?.[assetName]) {
23
- return types_1.Result.result(cached[assetName]);
19
+ return Result.result(cached[assetName]);
24
20
  }
25
- const { error, result: asset } = await (0, exports.internalGetCollectionAsset)(collectionName, assetName);
21
+ const { error, result: asset } = await internalGetCollectionAsset(collectionName, assetName);
26
22
  if (error) {
27
- return types_1.Result.error(error);
23
+ return Result.error(error);
28
24
  }
29
25
  assetsMemo.assets[collectionName] ??= {};
30
26
  assetsMemo.assets[collectionName][assetName] = asset;
31
- return types_1.Result.result(asset);
27
+ return Result.result(asset);
32
28
  };
33
- exports.getCollectionAsset = getCollectionAsset;
34
- const getFunction = async (collectionName, functionName, token, options = {
29
+ export const getFunction = async (collectionName, functionName, token, options = {
35
30
  exposedOnly: false,
36
31
  }) => {
37
- const { error, result: functions } = await (0, exports.getCollectionAsset)(collectionName, 'functions');
32
+ const { error, result: functions } = await getCollectionAsset(collectionName, 'functions');
38
33
  if (error) {
39
- return types_1.Result.error(error);
34
+ return Result.error(error);
40
35
  }
41
36
  if (!(functionName in functions)) {
42
- return types_1.Result.error(types_1.ACError.FunctionNotFound);
37
+ return Result.error(ACError.FunctionNotFound);
43
38
  }
44
- const collection = await (0, entrypoint_1.getCollection)(collectionName);
39
+ const collection = await getCollection(collectionName);
45
40
  const fn = functions[functionName];
46
41
  if (!collection) {
47
- return types_1.Result.error(types_1.ACError.ResourceNotFound);
42
+ return Result.error(ACError.ResourceNotFound);
48
43
  }
49
44
  if (options.exposedOnly) {
50
- const exposedStatus = await (0, accessControl_js_1.isFunctionExposed)(collection, functionName, token);
45
+ const exposedStatus = await isFunctionExposed(collection, functionName, token);
51
46
  switch (exposedStatus) {
52
- case accessControl_js_1.FunctionExposedStatus.FunctionNotExposed: return types_1.Result.error(types_1.ACError.FunctionNotExposed);
53
- case accessControl_js_1.FunctionExposedStatus.FunctionNotGranted: return types_1.Result.error(types_1.ACError.AuthorizationError);
47
+ case FunctionExposedStatus.FunctionNotExposed: return Result.error(ACError.FunctionNotExposed);
48
+ case FunctionExposedStatus.FunctionNotGranted: return Result.error(ACError.AuthorizationError);
54
49
  }
55
50
  }
56
51
  const wrapper = async (payload, context) => {
57
52
  const securityPolicy = collection.security?.functions?.[functionName];
58
53
  if (securityPolicy) {
59
54
  if (securityPolicy.rateLimiting) {
60
- const { error } = await (0, security_1.limitRate)(securityPolicy.rateLimiting, context);
55
+ const { error } = await limitRate(securityPolicy.rateLimiting, context);
61
56
  if (error) {
62
- return types_1.Result.error(error);
57
+ return Result.error(error);
63
58
  }
64
59
  }
65
60
  }
66
61
  return fn(payload, context);
67
62
  };
68
- return types_1.Result.result(wrapper);
63
+ return Result.result(wrapper);
69
64
  };
70
- exports.getFunction = getFunction;
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cascadingRemove = exports.preferredRemove = void 0;
4
- const mongodb_1 = require("mongodb");
5
- const context_js_1 = require("../context.js");
6
- const assets_js_1 = require("../assets.js");
7
- const database_js_1 = require("../database.js");
8
- const reference_js_1 = require("./reference.js");
1
+ import { ObjectId } from 'mongodb';
2
+ import { createContext } from '../context.js';
3
+ import { getFunction } from '../assets.js';
4
+ import { getDatabaseCollection } from '../database.js';
5
+ import { getReferences } from './reference.js';
9
6
  const internalCascadingRemove = async (target, refMap, context) => {
10
7
  for (const refName in refMap) {
11
8
  const reference = refMap[refName];
@@ -14,8 +11,8 @@ const internalCascadingRemove = async (target, refMap, context) => {
14
11
  }
15
12
  if (reference.referencedCollection) {
16
13
  if (reference.isInline || reference.referencedCollection === 'file') {
17
- if (target[refName] instanceof mongodb_1.ObjectId || Array.isArray(target[refName])) {
18
- await (0, exports.preferredRemove)(target[refName], reference, context);
14
+ if (target[refName] instanceof ObjectId || Array.isArray(target[refName])) {
15
+ await preferredRemove(target[refName], reference, context);
19
16
  }
20
17
  }
21
18
  }
@@ -30,12 +27,12 @@ const internalCascadingRemove = async (target, refMap, context) => {
30
27
  }
31
28
  }
32
29
  };
33
- const preferredRemove = async (targetId, reference, parentContext) => {
30
+ export const preferredRemove = async (targetId, reference, parentContext) => {
34
31
  if (!reference.referencedCollection) {
35
32
  return;
36
33
  }
37
- const coll = (0, database_js_1.getDatabaseCollection)(reference.referencedCollection);
38
- const context = await (0, context_js_1.createContext)({
34
+ const coll = getDatabaseCollection(reference.referencedCollection);
35
+ const context = await createContext({
39
36
  parentContext,
40
37
  collectionName: reference.referencedCollection,
41
38
  });
@@ -44,7 +41,7 @@ const preferredRemove = async (targetId, reference, parentContext) => {
44
41
  return;
45
42
  }
46
43
  const nonNullable = targetId.filter((id) => !!id);
47
- const { result: removeAll } = await (0, assets_js_1.getFunction)(reference.referencedCollection, 'removeAll');
44
+ const { result: removeAll } = await getFunction(reference.referencedCollection, 'removeAll');
48
45
  if (removeAll) {
49
46
  return removeAll({
50
47
  filters: nonNullable,
@@ -56,7 +53,7 @@ const preferredRemove = async (targetId, reference, parentContext) => {
56
53
  },
57
54
  });
58
55
  }
59
- const { result: remove } = await (0, assets_js_1.getFunction)(reference.referencedCollection, 'remove');
56
+ const { result: remove } = await getFunction(reference.referencedCollection, 'remove');
60
57
  if (remove) {
61
58
  return remove({
62
59
  filters: {
@@ -68,9 +65,7 @@ const preferredRemove = async (targetId, reference, parentContext) => {
68
65
  _id: targetId,
69
66
  });
70
67
  };
71
- exports.preferredRemove = preferredRemove;
72
- const cascadingRemove = async (target, context) => {
73
- const refMap = await (0, reference_js_1.getReferences)(context.description.properties);
68
+ export const cascadingRemove = async (target, context) => {
69
+ const refMap = await getReferences(context.description.properties);
74
70
  return internalCascadingRemove(target, refMap, context);
75
71
  };
76
- exports.cascadingRemove = cascadingRemove;
@@ -1,14 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extendCollection = exports.defineCollection = void 0;
4
- const common_1 = require("@aeriajs/common");
5
- const defineCollection = (collection) => {
1
+ import { deepMerge, freshItem } from '@aeriajs/common';
2
+ export const defineCollection = (collection) => {
6
3
  return Object.assign({
7
- item: (0, common_1.freshItem)(collection.description),
4
+ item: freshItem(collection.description),
8
5
  }, collection);
9
6
  };
10
- exports.defineCollection = defineCollection;
11
- const extendCollection = (left, right) => {
12
- return (0, common_1.deepMerge)(left, right);
7
+ export const extendCollection = (left, right) => {
8
+ return deepMerge(left, right);
13
9
  };
14
- exports.extendCollection = extendCollection;
@@ -1,12 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineDescriptionTuple = exports.defineDescription = void 0;
4
- const defineDescription = (description) => {
1
+ export const defineDescription = (description) => {
5
2
  return description;
6
3
  };
7
- exports.defineDescription = defineDescription;
8
- const defineDescriptionTuple = (description) => [
4
+ export const defineDescriptionTuple = (description) => [
9
5
  {},
10
6
  description,
11
7
  ];
12
- exports.defineDescriptionTuple = defineDescriptionTuple;
@@ -1,24 +1,8 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./cascadingRemove.js"), exports);
18
- __exportStar(require("./define.js"), exports);
19
- __exportStar(require("./description.js"), exports);
20
- __exportStar(require("./makePagination.js"), exports);
21
- __exportStar(require("./normalizeProjection.js"), exports);
22
- __exportStar(require("./preload.js"), exports);
23
- __exportStar(require("./reference.js"), exports);
24
- __exportStar(require("./traverseDocument.js"), exports);
1
+ export * from './cascadingRemove.js';
2
+ export * from './define.js';
3
+ export * from './description.js';
4
+ export * from './makePagination.js';
5
+ export * from './normalizeProjection.js';
6
+ export * from './preload.js';
7
+ export * from './reference.js';
8
+ export * from './traverseDocument.js';
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makePagination = void 0;
4
- const common_1 = require("@aeriajs/common");
5
- const count_js_1 = require("../functions/count.js");
6
- const makePagination = async (payload, documents, context) => {
1
+ import { throwIfError } from '@aeriajs/common';
2
+ import { count } from '../functions/count.js';
3
+ export const makePagination = async (payload, documents, context) => {
7
4
  const { offset = 0, limit = context.config.defaultPaginationLimit, } = payload;
8
5
  const recordsTotal = typeof context.collection.functions.count === 'function'
9
- ? (0, common_1.throwIfError)(await context.collection.functions.count({
6
+ ? throwIfError(await context.collection.functions.count({
10
7
  filters: payload.filters,
11
8
  }))
12
- : (0, common_1.throwIfError)(await (0, count_js_1.count)({
9
+ : throwIfError(await count({
13
10
  filters: payload.filters,
14
11
  }, context));
15
12
  return {
@@ -19,4 +16,3 @@ const makePagination = async (payload, documents, context) => {
19
16
  limit,
20
17
  };
21
18
  };
22
- exports.makePagination = makePagination;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeProjection = void 0;
4
- const normalizeProjection = (properties, description) => {
1
+ export const normalizeProjection = (properties, description) => {
5
2
  const target = Array.from(properties);
6
3
  if (target.length === 0) {
7
4
  target.push(...Object.keys(description.properties));
@@ -19,4 +16,3 @@ const normalizeProjection = (properties, description) => {
19
16
  ? undefined
20
17
  : projection;
21
18
  };
22
- exports.normalizeProjection = normalizeProjection;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.preloadDescription = exports.applyPreset = void 0;
4
- const common_1 = require("@aeriajs/common");
5
- const assets_js_1 = require("../assets.js");
6
- const index_js_1 = require("../presets/index.js");
1
+ import { getReferenceProperty, deepMerge, serialize } from '@aeriajs/common';
2
+ import { getCollectionAsset } from '../assets.js';
3
+ import { presets } from '../presets/index.js';
7
4
  const preloadMemo = {};
8
5
  const recurseProperty = async (_property, propName, description) => {
9
6
  const property = Object.assign({}, _property);
@@ -12,7 +9,7 @@ const recurseProperty = async (_property, propName, description) => {
12
9
  return property;
13
10
  }
14
11
  if ('properties' in property) {
15
- return (0, exports.preloadDescription)(property, {
12
+ return preloadDescription(property, {
16
13
  memoize: false,
17
14
  timestamps: false,
18
15
  });
@@ -23,10 +20,10 @@ const recurseProperty = async (_property, propName, description) => {
23
20
  readOnly: true,
24
21
  };
25
22
  }
26
- const reference = (0, common_1.getReferenceProperty)(property);
23
+ const reference = getReferenceProperty(property);
27
24
  if (reference) {
28
25
  if (!reference.indexes && !reference.inline) {
29
- const { error, result: referenceDescription } = await (0, assets_js_1.getCollectionAsset)(reference.$ref, 'description');
26
+ const { error, result: referenceDescription } = await getCollectionAsset(reference.$ref, 'description');
30
27
  if (error) {
31
28
  throw new Error(`description of ${reference.$ref} not found`);
32
29
  }
@@ -40,12 +37,12 @@ const recurseProperty = async (_property, propName, description) => {
40
37
  }
41
38
  return property;
42
39
  };
43
- const applyPreset = (entry, presetName, parentName) => {
44
- const preset = index_js_1.presets[presetName];
40
+ export const applyPreset = (entry, presetName, parentName) => {
41
+ const preset = presets[presetName];
45
42
  const presetObject = Object.assign({}, parentName
46
43
  ? preset[parentName]
47
44
  : preset);
48
- return (0, common_1.deepMerge)(entry, presetObject, {
45
+ return deepMerge(entry, presetObject, {
49
46
  callback: (_, left) => {
50
47
  if (left === null) {
51
48
  return left;
@@ -53,13 +50,12 @@ const applyPreset = (entry, presetName, parentName) => {
53
50
  },
54
51
  });
55
52
  };
56
- exports.applyPreset = applyPreset;
57
- const preloadDescription = async (originalDescription, options) => {
53
+ export const preloadDescription = async (originalDescription, options) => {
58
54
  const { memoize = !!originalDescription.$id, timestamps = true, } = options || {};
59
55
  if (memoize && preloadMemo[originalDescription.$id]) {
60
56
  const description = preloadMemo[originalDescription.$id];
61
57
  return (options?.serialize
62
- ? (0, common_1.serialize)(description)
58
+ ? serialize(description)
63
59
  : description);
64
60
  }
65
61
  const description = Object.assign({}, originalDescription);
@@ -74,7 +70,7 @@ const preloadDescription = async (originalDescription, options) => {
74
70
  descriptionPresets.push('timestamped');
75
71
  }
76
72
  if (descriptionPresets.length > 0) {
77
- const merge = descriptionPresets.reduce((a, presetName) => (0, exports.applyPreset)(a, presetName), description);
73
+ const merge = descriptionPresets.reduce((a, presetName) => applyPreset(a, presetName), description);
78
74
  Object.assign(description, merge);
79
75
  }
80
76
  if (description.properties) {
@@ -86,7 +82,6 @@ const preloadDescription = async (originalDescription, options) => {
86
82
  preloadMemo[originalDescription.$id] = description;
87
83
  }
88
84
  return (options?.serialize
89
- ? (0, common_1.serialize)(description)
85
+ ? serialize(description)
90
86
  : description);
91
87
  };
92
- exports.preloadDescription = preloadDescription;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLookupPipeline = exports.buildLookupPipeline = exports.recurseSetStage = exports.getReferences = void 0;
4
- const common_1 = require("@aeriajs/common");
5
- const assets_js_1 = require("../assets.js");
1
+ import { throwIfError, getReferenceProperty } from '@aeriajs/common';
2
+ import { getCollectionAsset } from '../assets.js';
6
3
  const getTempName = (path) => {
7
4
  return `_${path.map(([segment]) => segment).join('_')}`;
8
5
  };
9
6
  const referenceMemo = {};
10
7
  const lookupMemo = {};
11
- const getReferences = async (properties, options = {}) => {
8
+ export const getReferences = async (properties, options = {}) => {
12
9
  const { depth = 0, maxDepth = 3, memoize, populate, isArrayOrArrayElement, } = options;
13
10
  if (memoize) {
14
11
  if (referenceMemo[memoize]) {
@@ -18,17 +15,17 @@ const getReferences = async (properties, options = {}) => {
18
15
  const refMap = {};
19
16
  for (const [propName, property] of Object.entries(properties)) {
20
17
  const reference = {};
21
- const refProperty = (0, common_1.getReferenceProperty)(property);
18
+ const refProperty = getReferenceProperty(property);
22
19
  if (depth === maxDepth || (populate && !populate.includes(propName))) {
23
20
  continue;
24
21
  }
25
22
  if (refProperty) {
26
- const description = (0, common_1.throwIfError)(await (0, assets_js_1.getCollectionAsset)(refProperty.$ref, 'description'));
23
+ const description = throwIfError(await getCollectionAsset(refProperty.$ref, 'description'));
27
24
  if (refProperty.inline || refProperty.populate) {
28
25
  if (refProperty.populate && refProperty.populate.length === 0) {
29
26
  continue;
30
27
  }
31
- const deepReferences = await (0, exports.getReferences)(description.properties, {
28
+ const deepReferences = await getReferences(description.properties, {
32
29
  depth: depth + 1,
33
30
  maxDepth: refProperty.populateDepth || maxDepth,
34
31
  memoize: `${memoize}.${propName}`,
@@ -54,7 +51,7 @@ const getReferences = async (properties, options = {}) => {
54
51
  // })
55
52
  // }
56
53
  if ('properties' in entrypoint) {
57
- const deepReferences = await (0, exports.getReferences)(entrypoint.properties, {
54
+ const deepReferences = await getReferences(entrypoint.properties, {
58
55
  memoize: `${memoize}.${propName}`,
59
56
  });
60
57
  if (Object.keys(deepReferences).length > 0) {
@@ -90,8 +87,7 @@ const getReferences = async (properties, options = {}) => {
90
87
  }
91
88
  return refMap;
92
89
  };
93
- exports.getReferences = getReferences;
94
- const recurseSetStage = (reference, path, parentElem, options = {
90
+ export const recurseSetStage = (reference, path, parentElem, options = {
95
91
  noCond: false,
96
92
  }) => {
97
93
  const [refName, isRef] = path.at(-1);
@@ -137,7 +133,7 @@ const recurseSetStage = (reference, path, parentElem, options = {
137
133
  const newElemName = `${refName}__elem`;
138
134
  let mapIn;
139
135
  if (reference.referencedCollection) {
140
- mapIn = (0, exports.recurseSetStage)({
136
+ mapIn = recurseSetStage({
141
137
  ...reference,
142
138
  isArray: false,
143
139
  }, path, `$$${newElemName}`);
@@ -146,7 +142,7 @@ const recurseSetStage = (reference, path, parentElem, options = {
146
142
  mapIn = {
147
143
  $mergeObjects: [
148
144
  `$$${newElemName}`,
149
- (0, exports.recurseSetStage)({
145
+ recurseSetStage({
150
146
  ...reference,
151
147
  isArray: false,
152
148
  }, path, `$$${newElemName}`),
@@ -228,7 +224,7 @@ const recurseSetStage = (reference, path, parentElem, options = {
228
224
  ? parentElem
229
225
  : `${parentElem}.${subRefName}`;
230
226
  }
231
- const result = (0, exports.recurseSetStage)(subReference, path.concat([
227
+ const result = recurseSetStage(subReference, path.concat([
232
228
  [
233
229
  subRefName,
234
230
  'referencedCollection' in subReference,
@@ -247,7 +243,7 @@ const recurseSetStage = (reference, path, parentElem, options = {
247
243
  },
248
244
  {
249
245
  $mergeObjects: [
250
- (0, exports.recurseSetStage)({
246
+ recurseSetStage({
251
247
  ...reference,
252
248
  deepReferences: undefined,
253
249
  }, path, parentElem, {
@@ -284,8 +280,7 @@ const recurseSetStage = (reference, path, parentElem, options = {
284
280
  ],
285
281
  };
286
282
  };
287
- exports.recurseSetStage = recurseSetStage;
288
- const buildLookupPipeline = (refMap, options = {}) => {
283
+ export const buildLookupPipeline = (refMap, options = {}) => {
289
284
  const { rootPipeline = [], path = [], tempNames = [], project, memoize: memoizeId, } = options;
290
285
  const memoize = project
291
286
  ? `${memoizeId}-${project.sort().join('-')}`
@@ -310,12 +305,12 @@ const buildLookupPipeline = (refMap, options = {}) => {
310
305
  ],
311
306
  ]);
312
307
  if (reference.deepReferences) {
313
- (0, exports.buildLookupPipeline)(reference.deepReferences, {
308
+ buildLookupPipeline(reference.deepReferences, {
314
309
  rootPipeline,
315
310
  tempNames,
316
311
  path: newPath,
317
312
  });
318
- const result = (0, exports.recurseSetStage)(reference, newPath, `$${refName}`);
313
+ const result = recurseSetStage(reference, newPath, `$${refName}`);
319
314
  setProperties[refName] = result;
320
315
  }
321
316
  if (reference.referencedCollection) {
@@ -359,7 +354,7 @@ const buildLookupPipeline = (refMap, options = {}) => {
359
354
  },
360
355
  });
361
356
  if (!reference.deepReferences) {
362
- const result = (0, exports.recurseSetStage)(reference, newPath, `$${refName}`);
357
+ const result = recurseSetStage(reference, newPath, `$${refName}`);
363
358
  setProperties[refName] = result;
364
359
  }
365
360
  }
@@ -383,9 +378,7 @@ const buildLookupPipeline = (refMap, options = {}) => {
383
378
  }
384
379
  return pipeline;
385
380
  };
386
- exports.buildLookupPipeline = buildLookupPipeline;
387
- const getLookupPipeline = async (description, options) => {
388
- const refMap = await (0, exports.getReferences)(description.properties);
389
- return (0, exports.buildLookupPipeline)(refMap, options);
381
+ export const getLookupPipeline = async (description, options) => {
382
+ const refMap = await getReferences(description.properties);
383
+ return buildLookupPipeline(refMap, options);
390
384
  };
391
- exports.getLookupPipeline = getLookupPipeline;