@venizia/ardor-kernel 0.4.8-15 → 0.4.8-17

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/README.md CHANGED
@@ -18,15 +18,15 @@ which re-exports this package.
18
18
 
19
19
  | Area | Exports |
20
20
  |---|---|
21
- | Application | `AbstractArdorApplication`, `BaseArdorApplication` - an IGNIS inversion `Container` with `injectable()`, `service()`, `repository()`, `dataSource()` and `component()` helpers |
21
+ | Application | `AbstractArdorApplication` - an IGNIS inversion `Container` to extend with `getAppInfo()` and `bindContext()`. `BaseArdorApplication`, which also binds the default providers, lives in `@venizia/ardor-admin` and is exported from `@venizia/ardor` |
22
22
  | Services | `BaseService`, `DefaultAuthService`, `DefaultNetworkRequestService` |
23
23
  | Providers | `BaseProvider` |
24
24
  | Decorators | `api()` - logs and rethrows a failing API method; the IGNIS stereotypes it re-exports (`component`, `configuration`, `datasource`, `inject`, `injectable`, `model`, `provide`, `repository`, `service`) |
25
25
  | Bindings | `CoreBindings`, `LocalStorageKeys`, `BindingKeys`, `BindingNamespaces` |
26
26
  | Constants | `RequestMethods`, `RequestTypes`, `RequestBodyTypes`, `RequestCountData`, `HeaderConstants`, `Environments`, `App`, `Authentication`, `StorageAreas`, `RequestChannel` |
27
27
  | Network | `NetworkHeaders`, `RequestBodyEncoder`, `ResponseReader`, `AuthRecovery`, `AuthTokenStore` (the fetch transport is IGNIS's `NodeFetchNetworkRequest`) |
28
- | Utilities | `ValueUtility` (`isDefined`, `isString`, `isNumber`, `isObject`, `isValidDate`), `BrowserUtility.isBrowser`, `FileUtility.toDataUrl`, `RuntimeConfig.get` (with `RUNTIME_CONFIG_GLOBAL` and `RUNTIME_CONFIG_REQUIRED_CODE`), `BrowserStorage`, `BrowserClipboard`, `StorageCodecs`; the earlier bare names are removed (`bun run ardor codemod namespace` moves your code) |
29
- | Types | `IdType`, `AnyType`, `AnyObject`, `ValueOrPromise`, `ValueOf`, `TConstValue`, `TPaths`, `TFullPaths`, `ISendParams`, `IRestDataProviderOptions`, `IApplicationInfo`, ... |
28
+ | Utilities | `ValueUtility` (`isDefined`, `isString`, `isNumber`, `isObject`, `isValidDate`), `BrowserUtility.isBrowser`, `FileUtility.toDataUrl`, `RuntimeConfig.get` and `RuntimeConfig.getRequired` (with `RUNTIME_CONFIG_GLOBAL`, `RUNTIME_CONFIG_REQUIRED_CODE` and `RUNTIME_CONFIG_INVALID_CODE`), `BrowserStorage`, `BrowserClipboard`, `StorageCodecs`; the earlier bare names are removed (`bun run ardor codemod namespace` moves your code) |
29
+ | Types | `IdType`, `IAuthUser`, `ValueOrPromise`, `ValueOf`, `TConstValue`, `TPaths`, `TFullPaths`, `ISendParams`, `IRestDataProviderOptions`, `IApplicationInfo`, ... |
30
30
 
31
31
  ## License
32
32
 
@@ -1,5 +1,5 @@
1
1
  import { type Binding, Container, type TBindingScope, type TClass } from '@venizia/ignis-inversion';
2
- import { type IApplicationInfo, type IArdorApplication, type IArtifactIndex, type IFeatureBase, type ValueOrPromise } from '../../common/index.js';
2
+ import { type IApplicationInfo, type IArtifactIndex, type IFeatureBase, type ValueOrPromise } from '../../common/index.js';
3
3
  /** Per-registration choices for `service()`, `repository()`, `dataSource()` and `component()`. */
4
4
  export interface IArtifactRegistration {
5
5
  /** Bind under this key instead of `<namespace>.<ClassName>`. */
@@ -13,7 +13,8 @@ export interface IArtifactRegistration {
13
13
  */
14
14
  scope?: TBindingScope;
15
15
  /**
16
- * `false` refuses to replace a binding already under the key.
16
+ * `false` refuses to replace a binding already under the key, and keeps `bindingList()` from
17
+ * replacing this one; only `bindContext()` does.
17
18
  * @default true
18
19
  */
19
20
  allowOverride?: boolean;
@@ -23,23 +24,47 @@ export interface IArtifactRegistration {
23
24
  * `dataSource()`/`component()` by hand. Both record the key on the class. Every kind defaults to
24
25
  * SINGLETON (IGNIS's server uses transient): a hook resolves on every render.
25
26
  */
26
- export declare abstract class AbstractArdorApplication extends Container implements IArdorApplication {
27
+ export declare abstract class AbstractArdorApplication extends Container {
27
28
  /** The application's own bindings; `preConfigure` runs it last, so they win over discovered and feature bindings. */
28
29
  abstract bindContext(): ValueOrPromise<void>;
29
30
  /** The `IApplicationInfo` that `preConfigure` binds under `CoreBindings.APPLICATION_INFO`. */
30
31
  abstract getAppInfo(): ValueOrPromise<IApplicationInfo>;
31
32
  /** What `start()` resolved from `artifacts()`; unset when `preConfigure()` runs without it. */
32
33
  private resolvedIndexes;
34
+ /** The keys bound with `allowOverride: false`, each with the class that holds it; only `bindContext()` may replace them. */
35
+ private readonly lockedKeys;
33
36
  /** Stays synchronous unless `getAppInfo()` returns a promise: a subclass may still return either. */
34
37
  preConfigure(): ValueOrPromise<void>;
35
38
  private bindInfoAndArtifacts;
36
39
  /**
37
- * Binds every stereotyped class under its key and scope, then each `@provide` method under its
38
- * own key, as IGNIS's `bindProvidedKeys` does: a lazy provider, SINGLETON unless `scope` says
39
- * otherwise.
40
+ * Binds every stereotyped class whose `when` allows it, under its key and scope, then each
41
+ * `@provide` method under its own key, as IGNIS's `bindProvidedKeys` does: a lazy provider,
42
+ * SINGLETON unless `scope` says otherwise. `order` and `after` are not read: every binding is
43
+ * lazy, so registration order changes nothing.
40
44
  */
41
45
  registerArtifacts(): void;
42
- /** Classes bound under literal keys before `bindContext()` runs. */
46
+ /**
47
+ * Two different classes that end up on one key where at least one pinned it: the later import would
48
+ * silently win. Two derived keys are `ArtifactBindingKeys`'s to judge. Two pinned classes with one
49
+ * name are a hot reload that declared the class again, which leaves nothing to tell apart.
50
+ */
51
+ private assertNoPinnedCollision;
52
+ /**
53
+ * Whether two classes are one declaration evaluated twice, as a hot reload does: the same name and the same
54
+ * source text. Two different classes that share a name (a minifier does it) are not, and the later one would
55
+ * silently replace the earlier; two different classes with the same name and identical source text are taken as
56
+ * one, the price of allowing a hot reload.
57
+ */
58
+ private static isSameDeclaration;
59
+ /**
60
+ * Evaluates the `when` a stereotype declares, once, with the application. It must answer
61
+ * synchronously: a promise is refused rather than read as true.
62
+ */
63
+ private isSelected;
64
+ /**
65
+ * Classes bound under literal keys before `bindContext()` runs. A key that holds a class declared
66
+ * `allowOverride: false` throws; only `bindContext()` replaces it.
67
+ */
43
68
  bindingList(): Record<string, TClass<unknown>>;
44
69
  /**
45
70
  * The generated artifact indexes (`ignis-artifacts generate`). Discovery still binds every
@@ -62,8 +87,8 @@ export declare abstract class AbstractArdorApplication extends Container impleme
62
87
  private assertIndexed;
63
88
  /**
64
89
  * Binds the features after the stereotypes, so `bindingList()` and `bindContext()` still override
65
- * what a feature provides. A name is unique, and every configuration a feature lists must have
66
- * been discovered: one that was not means the feature's bindings were silently never made.
90
+ * what a feature provides. A name is unique, and every configuration and artifact a feature lists
91
+ * must have been discovered: one that was not means its binding was silently never made.
67
92
  */
68
93
  private registerFeatures;
69
94
  /** Runs after `preConfigure` in `start()`; empty by default, for a subclass to override. */
@@ -76,14 +101,16 @@ export declare abstract class AbstractArdorApplication extends Container impleme
76
101
  dataSource<T>(target: TClass<T>, opts?: IArtifactRegistration): Binding<T>;
77
102
  /** Binds `target` in the component namespace; returns the binding. */
78
103
  component<T>(target: TClass<T>, opts?: IArtifactRegistration): Binding<T>;
79
- /** `<scope>.<ClassName>`, singleton, with tags. Prefer the per-kind methods above. */
80
- injectable<T>(scope: string, value: TClass<T>, tags?: Array<string>): void;
104
+ /**
105
+ * The bindings a framework layer supplies before anything of the application, so a stereotype, a
106
+ * `@provide` method, a feature, `bindingList()` or `bindContext()` under the same key replaces
107
+ * them. Runs once `APPLICATION_INSTANCE` and `APPLICATION_INFO` are bound. Empty here: the
108
+ * `BaseArdorApplication` of `@venizia/ardor-admin` binds the default providers.
109
+ */
110
+ protected bindDefaults(): void;
81
111
  /** Resolves the artifact indexes, then runs `preConfigure`, then `postConfigure`, in that order. */
82
112
  start(): Promise<void>;
83
113
  /** Key: explicit `binding` > the class's stereotype > `<namespace>.<ClassName>`. Same for scope. */
84
114
  private registerArtifact;
85
115
  }
86
- /** The base to extend for an application: implement `bindContext` and `getAppInfo`. */
87
- export declare abstract class BaseArdorApplication extends AbstractArdorApplication {
88
- }
89
116
  //# sourceMappingURL=abstract.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import { ArtifactBindingKeys, ArtifactNamespaces, BindingNamespaces, MetadataRegistry, } from '@venizia/ignis-kernel/metadata';
2
2
  import { BindingScopes, Container, getError, } from '@venizia/ignis-inversion';
3
3
  import { CoreBindings, } from '../../common/index.js';
4
+ import { ApplicationInfoGuard } from './app-info.js';
4
5
  /** The six kinds of an artifact index, as `ignis-artifacts generate` emits them. */
5
6
  const ArtifactIndexKinds = [
6
7
  'configurations',
@@ -16,6 +17,11 @@ const ArtifactIndexKinds = [
16
17
  * SINGLETON (IGNIS's server uses transient): a hook resolves on every render.
17
18
  */
18
19
  export class AbstractArdorApplication extends Container {
20
+ constructor() {
21
+ super(...arguments);
22
+ /** The keys bound with `allowOverride: false`, each with the class that holds it; only `bindContext()` may replace them. */
23
+ this.lockedKeys = new Map();
24
+ }
19
25
  /** Stays synchronous unless `getAppInfo()` returns a promise: a subclass may still return either. */
20
26
  preConfigure() {
21
27
  this.bind({ key: CoreBindings.APPLICATION_INSTANCE }).toValue(this);
@@ -26,49 +32,72 @@ export class AbstractArdorApplication extends Container {
26
32
  return this.bindInfoAndArtifacts({ info });
27
33
  }
28
34
  bindInfoAndArtifacts(opts) {
35
+ ApplicationInfoGuard.assert({ info: opts.info });
29
36
  this.bind({ key: CoreBindings.APPLICATION_INFO }).toValue(opts.info);
30
- // Least explicit first, so the most explicit wins: stereotype, features, bindingList(), bindContext().
37
+ // Least explicit first, so the most explicit wins: defaults, stereotypes and @provide, features,
38
+ // bindingList(), bindContext().
39
+ this.bindDefaults();
31
40
  this.registerArtifacts();
32
41
  this.registerFeatures({ features: this.features() });
33
42
  for (const [key, target] of Object.entries(this.bindingList())) {
43
+ const holder = this.lockedKeys.get(key);
44
+ if (holder !== undefined) {
45
+ throw getError({
46
+ message: `[bindingList] '${key}' is held by ${holder.name} with allowOverride false, and bindingList() would replace it with ${target.name} | Bind it in bindContext() to override on purpose, or drop allowOverride: false`,
47
+ });
48
+ }
34
49
  this.getMetadataRegistry().setBindingKey({ target, key });
35
50
  this.bind({ key }).toClass(target).setScope(BindingScopes.SINGLETON);
36
51
  }
37
52
  return this.bindContext();
38
53
  }
39
54
  /**
40
- * Binds every stereotyped class under its key and scope, then each `@provide` method under its
41
- * own key, as IGNIS's `bindProvidedKeys` does: a lazy provider, SINGLETON unless `scope` says
42
- * otherwise.
55
+ * Binds every stereotyped class whose `when` allows it, under its key and scope, then each
56
+ * `@provide` method under its own key, as IGNIS's `bindProvidedKeys` does: a lazy provider,
57
+ * SINGLETON unless `scope` says otherwise. `order` and `after` are not read: every binding is
58
+ * lazy, so registration order changes nothing.
43
59
  */
44
60
  registerArtifacts() {
45
61
  const registry = MetadataRegistry.getInstance();
46
- const targets = registry.getDiscoveredArtifacts();
62
+ const discovered = registry.getDiscoveredArtifacts();
47
63
  this.assertIndexed({
48
64
  indexes: this.resolvedIndexes ?? this.artifacts(),
49
- discovered: new Set(targets),
65
+ discovered: new Set(discovered),
50
66
  });
67
+ const targets = discovered
68
+ .filter((target) => typeof target === 'function')
69
+ .filter((target) => this.isSelected({ target }));
51
70
  // Two classes a minifier named alike derive one key, and the second would silently replace the
52
71
  // first. Checked here, never at decoration, so a hot reload that re-decorates a class is no error.
53
- ArtifactBindingKeys.assertNoDerivedCollision({
54
- caller: 'registerArtifacts',
55
- entries: targets.flatMap((target) => {
56
- const metadata = registry.getArtifactMetadata({ target });
57
- if (!metadata) {
58
- return [];
59
- }
60
- const namespace = ArtifactNamespaces.resolve({ type: metadata.type });
61
- return [{ target: target, namespace, binding: metadata.binding }];
62
- }),
72
+ const entries = targets.flatMap((target) => {
73
+ const metadata = registry.getArtifactMetadata({ target });
74
+ if (!metadata) {
75
+ return [];
76
+ }
77
+ const namespace = ArtifactNamespaces.resolve({ type: metadata.type });
78
+ return [{ target, namespace, binding: metadata.binding }];
63
79
  });
80
+ ArtifactBindingKeys.assertNoDerivedCollision({ caller: 'registerArtifacts', entries });
81
+ this.assertNoPinnedCollision({ entries });
64
82
  for (const target of targets) {
65
83
  const key = this.getMetadataRegistry().getBindingKey({ target });
66
84
  if (!key) {
67
85
  continue;
68
86
  }
87
+ const metadata = registry.getArtifactMetadata({ target });
88
+ const holder = this.lockedKeys.get(key);
89
+ if (holder !== undefined &&
90
+ !AbstractArdorApplication.isSameDeclaration({ left: holder, right: target })) {
91
+ throw getError({
92
+ message: `[registerArtifacts] '${String(key)}' is held by ${holder.name} with allowOverride false, and ${target.name} would replace it | Give one of them another key, or bind the intended one in bindContext()`,
93
+ });
94
+ }
95
+ if (metadata?.allowOverride === false) {
96
+ this.lockedKeys.set(key, target);
97
+ }
69
98
  this.bind({ key })
70
99
  .toClass(target)
71
- .setScope(registry.getArtifactMetadata({ target })?.scope ?? BindingScopes.SINGLETON);
100
+ .setScope(metadata?.scope ?? BindingScopes.SINGLETON);
72
101
  for (const entry of registry.getProvideMetadata({ target })) {
73
102
  this.bind({ key: entry.key })
74
103
  .toProvider((container) => {
@@ -79,7 +108,73 @@ export class AbstractArdorApplication extends Container {
79
108
  }
80
109
  }
81
110
  }
82
- /** Classes bound under literal keys before `bindContext()` runs. */
111
+ /**
112
+ * Two different classes that end up on one key where at least one pinned it: the later import would
113
+ * silently win. Two derived keys are `ArtifactBindingKeys`'s to judge. Two pinned classes with one
114
+ * name are a hot reload that declared the class again, which leaves nothing to tell apart.
115
+ */
116
+ assertNoPinnedCollision(opts) {
117
+ const owners = new Map();
118
+ for (const entry of opts.entries) {
119
+ const { key, isDerived } = ArtifactBindingKeys.resolve(entry);
120
+ const owner = owners.get(key);
121
+ owners.set(key, { target: entry.target, isDerived });
122
+ if (!owner || owner.target === entry.target) {
123
+ continue;
124
+ }
125
+ const isSameDeclaration = !owner.isDerived &&
126
+ !isDerived &&
127
+ AbstractArdorApplication.isSameDeclaration({ left: owner.target, right: entry.target });
128
+ if ((owner.isDerived && isDerived) || isSameDeclaration) {
129
+ continue;
130
+ }
131
+ throw getError({
132
+ message: `[registerArtifacts] The key '${key}' is claimed by both ${owner.target.name} and ${entry.target.name}, and the one imported last would silently replace the other | Give one of them another key, select one with 'when', or bind the intended one in bindContext()`,
133
+ });
134
+ }
135
+ }
136
+ /**
137
+ * Whether two classes are one declaration evaluated twice, as a hot reload does: the same name and the same
138
+ * source text. Two different classes that share a name (a minifier does it) are not, and the later one would
139
+ * silently replace the earlier; two different classes with the same name and identical source text are taken as
140
+ * one, the price of allowing a hot reload.
141
+ */
142
+ static isSameDeclaration(opts) {
143
+ const { left, right } = opts;
144
+ return (left === right ||
145
+ (left.name === right.name &&
146
+ Function.prototype.toString.call(left) === Function.prototype.toString.call(right)));
147
+ }
148
+ /**
149
+ * Evaluates the `when` a stereotype declares, once, with the application. It must answer
150
+ * synchronously: a promise is refused rather than read as true.
151
+ */
152
+ isSelected(opts) {
153
+ const { target } = opts;
154
+ const when = MetadataRegistry.getInstance().getArtifactMetadata({ target })?.when;
155
+ if (when === undefined) {
156
+ return true;
157
+ }
158
+ let selected;
159
+ try {
160
+ selected = when({ application: this });
161
+ }
162
+ catch (error) {
163
+ throw getError({
164
+ message: `[registerArtifacts] The 'when' of ${target.name} threw: ${error instanceof Error ? error.message : String(error)} | A 'when' must not throw: return false to leave the class out`,
165
+ });
166
+ }
167
+ if (typeof selected !== 'boolean') {
168
+ throw getError({
169
+ message: `[registerArtifacts] The 'when' of ${target.name} must return a boolean synchronously, it returned ${selected instanceof Promise ? 'a Promise' : typeof selected} | Resolve the answer before decoration, or bind the class by hand in bindContext()`,
170
+ });
171
+ }
172
+ return selected;
173
+ }
174
+ /**
175
+ * Classes bound under literal keys before `bindContext()` runs. A key that holds a class declared
176
+ * `allowOverride: false` throws; only `bindContext()` replaces it.
177
+ */
83
178
  bindingList() {
84
179
  return {};
85
180
  }
@@ -152,8 +247,8 @@ export class AbstractArdorApplication extends Container {
152
247
  }
153
248
  /**
154
249
  * Binds the features after the stereotypes, so `bindingList()` and `bindContext()` still override
155
- * what a feature provides. A name is unique, and every configuration a feature lists must have
156
- * been discovered: one that was not means the feature's bindings were silently never made.
250
+ * what a feature provides. A name is unique, and every configuration and artifact a feature lists
251
+ * must have been discovered: one that was not means its binding was silently never made.
157
252
  */
158
253
  registerFeatures(opts) {
159
254
  const { features } = opts;
@@ -173,6 +268,20 @@ export class AbstractArdorApplication extends Container {
173
268
  });
174
269
  }
175
270
  }
271
+ for (const group of ArtifactIndexKinds) {
272
+ for (const [position, target] of (feature.artifacts?.[group] ?? []).entries()) {
273
+ if (typeof target !== 'function') {
274
+ throw getError({
275
+ message: `[features] '${feature.name}' lists an entry in artifacts.${group} that is not a class (position ${position}) | Usually an import cycle: the feature module must not be imported by the classes it lists`,
276
+ });
277
+ }
278
+ if (!discovered.has(target)) {
279
+ throw getError({
280
+ message: `[features] '${feature.name}' lists ${target.name} in artifacts.${group}, which was never discovered | Decorate it with its stereotype and import its module before start()`,
281
+ });
282
+ }
283
+ }
284
+ }
176
285
  }
177
286
  this.bind({ key: CoreBindings.FEATURES }).toValue(features);
178
287
  }
@@ -214,15 +323,13 @@ export class AbstractArdorApplication extends Container {
214
323
  opts,
215
324
  });
216
325
  }
217
- /** `<scope>.<ClassName>`, singleton, with tags. Prefer the per-kind methods above. */
218
- injectable(scope, value, tags) {
219
- const { key } = ArtifactBindingKeys.resolve({ target: value, namespace: scope });
220
- this.getMetadataRegistry().setBindingKey({ target: value, key });
221
- this.bind({ key })
222
- .toClass(value)
223
- .setScope(BindingScopes.SINGLETON)
224
- .setTags(...(tags ?? []));
225
- }
326
+ /**
327
+ * The bindings a framework layer supplies before anything of the application, so a stereotype, a
328
+ * `@provide` method, a feature, `bindingList()` or `bindContext()` under the same key replaces
329
+ * them. Runs once `APPLICATION_INSTANCE` and `APPLICATION_INFO` are bound. Empty here: the
330
+ * `BaseArdorApplication` of `@venizia/ardor-admin` binds the default providers.
331
+ */
332
+ bindDefaults() { }
226
333
  /** Resolves the artifact indexes, then runs `preConfigure`, then `postConfigure`, in that order. */
227
334
  async start() {
228
335
  const result = await this.resolveArtifactIndexes();
@@ -245,13 +352,13 @@ export class AbstractArdorApplication extends Container {
245
352
  message: `[${caller}] '${key}' is already bound and allowOverride is false | Pass a distinct binding key`,
246
353
  });
247
354
  }
355
+ if (!allowOverride) {
356
+ this.lockedKeys.set(key, target);
357
+ }
248
358
  this.getMetadataRegistry().setBindingKey({ target, key });
249
359
  return this.bind({ key })
250
360
  .toClass(target)
251
361
  .setScope(opts.opts?.scope ?? declared?.scope ?? BindingScopes.SINGLETON);
252
362
  }
253
363
  }
254
- /** The base to extend for an application: implement `bindContext` and `getAppInfo`. */
255
- export class BaseArdorApplication extends AbstractArdorApplication {
256
- }
257
364
  //# sourceMappingURL=abstract.js.map
@@ -0,0 +1,8 @@
1
+ /** Checks the `IApplicationInfo` that `getAppInfo()` returned, so `start()` rejects a bad one at boot. */
2
+ export declare class ApplicationInfoGuard {
3
+ /** Throws an `ApplicationError` when `name` is not a non-blank string, `version` is not a string, or `id` is not a valid scope id. */
4
+ static assert(opts: {
5
+ info: unknown;
6
+ }): void;
7
+ }
8
+ //# sourceMappingURL=app-info.d.ts.map
@@ -0,0 +1,38 @@
1
+ import { getError } from '@venizia/ignis-inversion';
2
+ import { LocalStorageKeys } from '../../common/index.js';
3
+ /** Checks the `IApplicationInfo` that `getAppInfo()` returned, so `start()` rejects a bad one at boot. */
4
+ export class ApplicationInfoGuard {
5
+ /** Throws an `ApplicationError` when `name` is not a non-blank string, `version` is not a string, or `id` is not a valid scope id. */
6
+ static assert(opts) {
7
+ const { info } = opts;
8
+ if (typeof info !== 'object' || info === null) {
9
+ throw getError({
10
+ message: '[appInfo] getAppInfo() must return an object | Return { name, version, description }',
11
+ });
12
+ }
13
+ const name = Reflect.get(info, 'name');
14
+ const version = Reflect.get(info, 'version');
15
+ const id = Reflect.get(info, 'id');
16
+ if (typeof name !== 'string' || name.trim() === '') {
17
+ throw getError({
18
+ message: '[appInfo] IApplicationInfo.name must be a non-empty string | Set the name in getAppInfo()',
19
+ });
20
+ }
21
+ if (typeof version !== 'string') {
22
+ throw getError({
23
+ message: '[appInfo] IApplicationInfo.version must be a string | Set the version in getAppInfo()',
24
+ });
25
+ }
26
+ if (id === undefined) {
27
+ return;
28
+ }
29
+ if (typeof id !== 'string') {
30
+ throw getError({
31
+ message: '[appInfo] IApplicationInfo.id must be a string | Set the id in getAppInfo(), or leave it out',
32
+ });
33
+ }
34
+ // Throws for an id that is not letters, digits, '.', '_' and '-'.
35
+ LocalStorageKeys.scoped({ id });
36
+ }
37
+ }
38
+ //# sourceMappingURL=app-info.js.map
@@ -7,4 +7,5 @@ export { ArtifactBindingKeys, ArtifactNamespaces, ArtifactTypes, BindingKeys, Bi
7
7
  export type { IArtifactMetadata, IArtifactRegistrationOptions, TBindingNamespace, TBindingScope, } from '@venizia/ignis-kernel/metadata';
8
8
  export { RepositoryTypes } from '@venizia/ignis-kernel/repository';
9
9
  export type { TRepositoryType } from '@venizia/ignis-kernel/repository';
10
+ export { provideOption } from './provide-option.js';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -6,4 +6,5 @@ export { component, configuration, datasource, inject, injectable, model, provid
6
6
  export { ArtifactBindingKeys, ArtifactNamespaces, ArtifactTypes, BindingKeys, BindingNamespaces, } from '@venizia/ignis-kernel/metadata';
7
7
  // The `type` of `@repository`: `REMOTE` for an `HttpRepository`, which has no model.
8
8
  export { RepositoryTypes } from '@venizia/ignis-kernel/repository';
9
+ export { provideOption } from './provide-option.js';
9
10
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,28 @@
1
+ import type { ICoreOptionTypes } from '../../common/index.js';
2
+ /**
3
+ * `@provide` for an options key of `CoreBindings`: the method must return the options type of that
4
+ * key (`ICoreOptionTypes`), so a wrong return type fails at compile time instead of mid-render.
5
+ * The method is synchronous: the container does not await a provider.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import {
10
+ * configuration,
11
+ * CoreBindings,
12
+ * provideOption,
13
+ * type IRestDataProviderOptions,
14
+ * } from '@venizia/ardor';
15
+ *
16
+ * @configuration()
17
+ * export class ApiConfiguration {
18
+ * @provideOption({ key: CoreBindings.REST_DATA_PROVIDER_OPTIONS })
19
+ * restDataProviderOptions(): IRestDataProviderOptions {
20
+ * return { url: 'https://api.example.com' };
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ export declare const provideOption: <K extends keyof ICoreOptionTypes>(opts: {
26
+ key: K;
27
+ }) => (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<() => ICoreOptionTypes[K]>) => void;
28
+ //# sourceMappingURL=provide-option.d.ts.map
@@ -0,0 +1,30 @@
1
+ import { provide } from '@venizia/ignis-kernel/metadata';
2
+ /**
3
+ * `@provide` for an options key of `CoreBindings`: the method must return the options type of that
4
+ * key (`ICoreOptionTypes`), so a wrong return type fails at compile time instead of mid-render.
5
+ * The method is synchronous: the container does not await a provider.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import {
10
+ * configuration,
11
+ * CoreBindings,
12
+ * provideOption,
13
+ * type IRestDataProviderOptions,
14
+ * } from '@venizia/ardor';
15
+ *
16
+ * @configuration()
17
+ * export class ApiConfiguration {
18
+ * @provideOption({ key: CoreBindings.REST_DATA_PROVIDER_OPTIONS })
19
+ * restDataProviderOptions(): IRestDataProviderOptions {
20
+ * return { url: 'https://api.example.com' };
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ export const provideOption = (opts) => {
26
+ return (target, propertyKey, descriptor) => {
27
+ provide({ key: opts.key })(target, propertyKey, descriptor);
28
+ };
29
+ };
30
+ //# sourceMappingURL=provide-option.js.map
@@ -1,2 +1,3 @@
1
1
  export * from './base.js';
2
+ export * from './role-permission.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export * from './base.js';
2
+ export * from './role-permission.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,59 @@
1
+ import { BaseHelper } from '@venizia/ignis-helpers/core';
2
+ import { type IPermissionProvider, type IRolePermissionProviderOptions } from '../../common/index.js';
3
+ import type { DefaultAuthService } from '../services/auth.js';
4
+ /**
5
+ * An `IPermissionProvider` over a table the application writes: each role name holds grant patterns,
6
+ * and a user may do what any of the roles from `DefaultAuthService.getRoles` grants. Nothing else is
7
+ * allowed: no signed-in user, no roles, or a role without an entry is denied. The roles are read at
8
+ * every call and are the ones stored at sign-in; a token refresh keeps them.
9
+ *
10
+ * It is opt-in: ARDOR binds none, and unbound means every check passes. An application with other
11
+ * needs writes its own `IPermissionProvider` and binds that under `CoreBindings.PERMISSION_PROVIDER`.
12
+ * The roles are data in the browser: this decides what the interface shows, never what a user may
13
+ * do, and the backend must check every request.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { BindingScopes } from '@venizia/ignis-inversion';
18
+ * import {
19
+ * BaseArdorApplication,
20
+ * configuration,
21
+ * CoreBindings,
22
+ * provideOption,
23
+ * RolePermissionProvider,
24
+ * type IApplicationInfo,
25
+ * type IRolePermissionProviderOptions,
26
+ * } from '@venizia/ardor';
27
+ *
28
+ * @configuration()
29
+ * export class PermissionConfiguration {
30
+ * @provideOption({ key: CoreBindings.PERMISSION_PROVIDER_OPTIONS })
31
+ * permissionOptions(): IRolePermissionProviderOptions {
32
+ * return { grants: { admin: ['*'], editor: ['orders.*', 'stocks.list'] } };
33
+ * }
34
+ * }
35
+ *
36
+ * export class Application extends BaseArdorApplication {
37
+ * getAppInfo(): IApplicationInfo {
38
+ * return { name: 'shop', version: '1.0.0', description: 'A shop back office' };
39
+ * }
40
+ *
41
+ * bindContext(): void {
42
+ * this.bind({ key: CoreBindings.PERMISSION_PROVIDER })
43
+ * .toClass(RolePermissionProvider)
44
+ * .setScope(BindingScopes.SINGLETON);
45
+ * }
46
+ * }
47
+ * ```
48
+ */
49
+ export declare class RolePermissionProvider extends BaseHelper implements IPermissionProvider {
50
+ private readonly authService;
51
+ private readonly grants;
52
+ constructor(authService: DefaultAuthService, options: IRolePermissionProviderOptions);
53
+ canAccess(opts: {
54
+ resource: string;
55
+ action: string;
56
+ record?: unknown;
57
+ }): Promise<boolean>;
58
+ }
59
+ //# sourceMappingURL=role-permission.d.ts.map