@aeriajs/entrypoint 0.0.163 → 0.0.164

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/index.js CHANGED
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAvailableRoles = exports.getConfig = exports.getRouter = exports.getCollection = exports.getCollections = exports.getEntrypoint = exports.getEntrypointPath = void 0;
4
- const path = require("node:path");
5
- const fs = require("node:fs/promises");
6
- const common_1 = require("@aeriajs/common");
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs/promises';
7
3
  let collectionsMemo;
8
4
  let availableRolesMemo;
9
5
  const collectionMemo = {};
@@ -12,7 +8,7 @@ const DEFAULT_CONFIG = {
12
8
  mutableUserProperties: [],
13
9
  },
14
10
  };
15
- const getEntrypointPath = async () => {
11
+ export const getEntrypointPath = async () => {
16
12
  if (process.env.AERIA_MAIN) {
17
13
  return path.join(process.cwd(), process.env.AERIA_MAIN);
18
14
  }
@@ -21,34 +17,31 @@ const getEntrypointPath = async () => {
21
17
  }));
22
18
  return path.join(process.cwd(), aeriaMain || main);
23
19
  };
24
- exports.getEntrypointPath = getEntrypointPath;
25
- const getEntrypoint = async () => {
26
- const entrypoint = await (0, common_1.dynamicImport)(await (0, exports.getEntrypointPath)());
20
+ export const getEntrypoint = async () => {
21
+ const entrypoint = await import(await getEntrypointPath());
27
22
  return entrypoint.default.default
28
23
  ? entrypoint.default
29
24
  : entrypoint;
30
25
  };
31
- exports.getEntrypoint = getEntrypoint;
32
26
  const internalGetCollections = async () => {
33
- const entrypoint = await (0, exports.getEntrypoint)();
27
+ const entrypoint = await getEntrypoint();
34
28
  const collections = entrypoint.collections
35
29
  ? entrypoint.collections
36
30
  : entrypoint.default.options.collections;
37
31
  return Object.assign({}, collections);
38
32
  };
39
- const getCollections = async () => {
33
+ export const getCollections = async () => {
40
34
  if (collectionsMemo) {
41
35
  return collectionsMemo;
42
36
  }
43
37
  collectionsMemo = await internalGetCollections();
44
38
  return Object.freeze(collectionsMemo);
45
39
  };
46
- exports.getCollections = getCollections;
47
- const getCollection = async (collectionName) => {
40
+ export const getCollection = async (collectionName) => {
48
41
  if (collectionMemo[collectionName]) {
49
42
  return collectionMemo[collectionName];
50
43
  }
51
- const collections = await (0, exports.getCollections)();
44
+ const collections = await getCollections();
52
45
  const candidate = collectionName in collections
53
46
  ? collections[collectionName]
54
47
  : undefined;
@@ -60,9 +53,8 @@ const getCollection = async (collectionName) => {
60
53
  }
61
54
  return Object.assign({}, collection);
62
55
  };
63
- exports.getCollection = getCollection;
64
- const getRouter = async () => {
65
- const entrypoint = await (0, exports.getEntrypoint)();
56
+ export const getRouter = async () => {
57
+ const entrypoint = await getEntrypoint();
66
58
  if (entrypoint.router) {
67
59
  return entrypoint.router;
68
60
  }
@@ -70,19 +62,17 @@ const getRouter = async () => {
70
62
  ? entrypoint.default.options.router
71
63
  : null;
72
64
  };
73
- exports.getRouter = getRouter;
74
- const getConfig = async () => {
75
- const entrypoint = await (0, exports.getEntrypoint)();
65
+ export const getConfig = async () => {
66
+ const entrypoint = await getEntrypoint();
76
67
  return entrypoint.default
77
68
  ? entrypoint.default.options.config
78
69
  : DEFAULT_CONFIG;
79
70
  };
80
- exports.getConfig = getConfig;
81
- const getAvailableRoles = async () => {
71
+ export const getAvailableRoles = async () => {
82
72
  if (availableRolesMemo) {
83
73
  return availableRolesMemo;
84
74
  }
85
- const collections = await (0, exports.getCollections)();
75
+ const collections = await getCollections();
86
76
  const availableRoles = [];
87
77
  if ('user' in collections) {
88
78
  const collection = typeof collections.user === 'function'
@@ -114,4 +104,3 @@ const getAvailableRoles = async () => {
114
104
  availableRolesMemo = Array.from(rolesSet);
115
105
  return availableRolesMemo;
116
106
  };
117
- exports.getAvailableRoles = getAvailableRoles;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@aeriajs/entrypoint",
3
- "version": "0.0.163",
3
+ "type": "module",
4
+ "version": "0.0.164",
4
5
  "description": "",
5
6
  "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -14,8 +14,7 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "types": "./dist/index.d.ts",
17
- "import": "./dist/index.mjs",
18
- "require": "./dist/index.js"
17
+ "default": "./dist/index.js"
19
18
  }
20
19
  },
21
20
  "files": [
@@ -26,17 +25,14 @@
26
25
  "@aeriajs/types": "link:../types"
27
26
  },
28
27
  "peerDependencies": {
29
- "@aeriajs/common": "^0.0.157",
30
- "@aeriajs/types": "^0.0.135"
28
+ "@aeriajs/common": "^0.0.158",
29
+ "@aeriajs/types": "^0.0.136"
31
30
  },
32
31
  "scripts": {
33
32
  "test": "vitest run",
34
33
  "test:typecheck": "tsc -p tsconfig.test.json",
35
34
  "lint": "eslint .",
36
35
  "lint:fix": "eslint . --fix",
37
- "build": "pnpm build:cjs && pnpm build:esm",
38
- "build:cjs": "tsc",
39
- "build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
40
- "build:esm-transform": "pnpm -w esm-transform $PWD/dist"
36
+ "build": "tsc"
41
37
  }
42
38
  }
package/dist/index.mjs DELETED
@@ -1,90 +0,0 @@
1
- "use strict";
2
- import * as path from "node:path";
3
- import * as fs from "node:fs/promises";
4
- import { dynamicImport } from "@aeriajs/common";
5
- let collectionsMemo;
6
- let availableRolesMemo;
7
- const collectionMemo = {};
8
- const DEFAULT_CONFIG = {
9
- security: {
10
- mutableUserProperties: []
11
- }
12
- };
13
- export const getEntrypointPath = async () => {
14
- if (process.env.AERIA_MAIN) {
15
- return path.join(process.cwd(), process.env.AERIA_MAIN);
16
- }
17
- const { main, aeriaMain } = JSON.parse(await fs.readFile(path.join(process.cwd(), "package.json"), {
18
- encoding: "utf8"
19
- }));
20
- return path.join(process.cwd(), aeriaMain || main);
21
- };
22
- export const getEntrypoint = async () => {
23
- const entrypoint = await dynamicImport(await getEntrypointPath());
24
- return entrypoint.default.default ? entrypoint.default : entrypoint;
25
- };
26
- const internalGetCollections = async () => {
27
- const entrypoint = await getEntrypoint();
28
- const collections = entrypoint.collections ? entrypoint.collections : entrypoint.default.options.collections;
29
- return Object.assign({}, collections);
30
- };
31
- export const getCollections = async () => {
32
- if (collectionsMemo) {
33
- return collectionsMemo;
34
- }
35
- collectionsMemo = await internalGetCollections();
36
- return Object.freeze(collectionsMemo);
37
- };
38
- export const getCollection = async (collectionName) => {
39
- if (collectionMemo[collectionName]) {
40
- return collectionMemo[collectionName];
41
- }
42
- const collections = await getCollections();
43
- const candidate = collectionName in collections ? collections[collectionName] : void 0;
44
- const collection = typeof candidate === "function" ? candidate() : candidate;
45
- if (collection) {
46
- collectionMemo[collectionName] = collection;
47
- }
48
- return Object.assign({}, collection);
49
- };
50
- export const getRouter = async () => {
51
- const entrypoint = await getEntrypoint();
52
- if (entrypoint.router) {
53
- return entrypoint.router;
54
- }
55
- return entrypoint.default ? entrypoint.default.options.router : null;
56
- };
57
- export const getConfig = async () => {
58
- const entrypoint = await getEntrypoint();
59
- return entrypoint.default ? entrypoint.default.options.config : DEFAULT_CONFIG;
60
- };
61
- export const getAvailableRoles = async () => {
62
- if (availableRolesMemo) {
63
- return availableRolesMemo;
64
- }
65
- const collections = await getCollections();
66
- const availableRoles = [];
67
- if ("user" in collections) {
68
- const collection = typeof collections.user === "function" ? collections.user() : collections.user;
69
- if ("roles" in collection.description.properties && "items" in collection.description.properties.roles && "enum" in collection.description.properties.roles.items) {
70
- availableRoles.push(...collection.description.properties.roles.items.enum);
71
- }
72
- }
73
- for (const collectionName in collections) {
74
- const candidate = collections[collectionName];
75
- const collection = typeof candidate === "function" ? candidate() : candidate;
76
- if (!collection.exposedFunctions) {
77
- continue;
78
- }
79
- for (const fnName in collection.exposedFunctions) {
80
- const exposed = collection.exposedFunctions[fnName];
81
- if (Array.isArray(exposed)) {
82
- availableRoles.push(...exposed);
83
- }
84
- }
85
- }
86
- const rolesSet = new Set(availableRoles);
87
- rolesSet.delete("unauthenticated");
88
- availableRolesMemo = Array.from(rolesSet);
89
- return availableRolesMemo;
90
- };