@arcote.tech/arc 0.1.12 → 0.3.0

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 (154) hide show
  1. package/dist/adapters/auth-adapter.d.ts +47 -0
  2. package/dist/adapters/command-wire.d.ts +28 -0
  3. package/dist/adapters/event-publisher.d.ts +106 -0
  4. package/dist/adapters/event-wire.d.ts +79 -0
  5. package/dist/adapters/index.d.ts +18 -0
  6. package/dist/adapters/wire.d.ts +20 -0
  7. package/dist/context/context.d.ts +49 -52
  8. package/dist/context/index.d.ts +1 -10
  9. package/dist/context-element/command/command-context.d.ts +71 -0
  10. package/dist/context-element/command/command-data.d.ts +33 -0
  11. package/dist/context-element/command/command-handler.d.ts +6 -0
  12. package/dist/context-element/command/command.d.ts +198 -0
  13. package/dist/context-element/command/index.d.ts +6 -0
  14. package/dist/context-element/context-element.d.ts +75 -0
  15. package/dist/context-element/event/event-data.d.ts +35 -0
  16. package/dist/context-element/event/event.d.ts +158 -0
  17. package/dist/context-element/event/index.d.ts +5 -0
  18. package/dist/context-element/event/instance.d.ts +26 -0
  19. package/dist/context-element/index.d.ts +10 -0
  20. package/dist/context-element/view/index.d.ts +5 -0
  21. package/dist/context-element/view/view-context.d.ts +51 -0
  22. package/dist/context-element/view/view-data.d.ts +40 -0
  23. package/dist/context-element/view/view.d.ts +194 -0
  24. package/dist/data-storage/data-storage-forked.d.ts +1 -1
  25. package/dist/data-storage/data-storage-master.d.ts +7 -10
  26. package/dist/data-storage/data-storage-observable.d.ts +61 -0
  27. package/dist/data-storage/data-storage.abstract.d.ts +1 -1
  28. package/dist/{db/interface.d.ts → data-storage/database-adapter.d.ts} +8 -3
  29. package/dist/{database → data-storage}/database-store.d.ts +45 -0
  30. package/dist/data-storage/{types.d.ts → find-options.d.ts} +1 -1
  31. package/dist/data-storage/index.d.ts +6 -2
  32. package/dist/{db/postgresAdapter.d.ts → data-storage/postgresql-adapter.d.ts} +7 -33
  33. package/dist/data-storage/query-result-resolver.d.ts +18 -0
  34. package/dist/data-storage/query-result-resolver.test.d.ts +2 -0
  35. package/dist/{db/sqliteAdapter.d.ts → data-storage/sqlite-adapter.d.ts} +5 -31
  36. package/dist/data-storage/store-state-fork.d.ts +1 -1
  37. package/dist/data-storage/store-state-master.d.ts +6 -2
  38. package/dist/data-storage/store-state.abstract.d.ts +1 -1
  39. package/dist/elements/abstract.d.ts +1 -1
  40. package/dist/elements/any.d.ts +1 -1
  41. package/dist/elements/array.d.ts +5 -5
  42. package/dist/elements/blob.d.ts +1 -1
  43. package/dist/elements/boolean.d.ts +1 -1
  44. package/dist/elements/branded.d.ts +5 -5
  45. package/dist/elements/date.d.ts +1 -1
  46. package/dist/elements/default.d.ts +5 -5
  47. package/dist/elements/file.d.ts +1 -1
  48. package/dist/elements/id.d.ts +3 -3
  49. package/dist/elements/index.d.ts +1 -0
  50. package/dist/elements/number.d.ts +1 -1
  51. package/dist/elements/object.d.ts +11 -10
  52. package/dist/elements/optional.d.ts +5 -5
  53. package/dist/elements/or.d.ts +5 -5
  54. package/dist/elements/record.d.ts +3 -3
  55. package/dist/elements/string-enum.d.ts +1 -1
  56. package/dist/elements/string.d.ts +1 -1
  57. package/dist/index.d.ts +8 -7
  58. package/dist/index.js +2373 -3439
  59. package/dist/model/index.d.ts +2 -0
  60. package/dist/model/live-query/index.d.ts +2 -0
  61. package/dist/model/live-query/live-query.d.ts +31 -0
  62. package/dist/model/live-query/query-cache.d.ts +60 -0
  63. package/dist/model/model-adapters.d.ts +13 -0
  64. package/dist/model/model.d.ts +19 -78
  65. package/dist/model/mutation-executor/index.d.ts +2 -0
  66. package/dist/model/mutation-executor/mutation-executor.d.ts +29 -0
  67. package/dist/token/index.d.ts +41 -0
  68. package/dist/token/secured-data-storage.d.ts +125 -0
  69. package/dist/token/token-cache.d.ts +100 -0
  70. package/dist/token/token-data.d.ts +38 -0
  71. package/dist/token/token-instance.d.ts +71 -0
  72. package/dist/token/token.d.ts +127 -0
  73. package/dist/utils/index.d.ts +4 -0
  74. package/dist/utils/types/add-question-marks.d.ts +9 -0
  75. package/dist/utils/types/first-argument.d.ts +5 -0
  76. package/dist/utils/types/get-type.d.ts +13 -0
  77. package/dist/utils/types/index.d.ts +6 -0
  78. package/dist/utils/types/merge.d.ts +7 -0
  79. package/dist/utils/types/object-util.d.ts +6 -0
  80. package/dist/utils/types/simplify.d.ts +7 -0
  81. package/package.json +10 -6
  82. package/dist/command/command-definition.d.ts +0 -5
  83. package/dist/command/command.d.ts +0 -45
  84. package/dist/command/index.d.ts +0 -2
  85. package/dist/context/commands.d.ts +0 -12
  86. package/dist/context/element.d.ts +0 -80
  87. package/dist/context/event.d.ts +0 -45
  88. package/dist/context/query-builder-context.d.ts +0 -15
  89. package/dist/context/query-builders.d.ts +0 -17
  90. package/dist/context/query-cache.d.ts +0 -9
  91. package/dist/context/query.d.ts +0 -12
  92. package/dist/context/reactive-query.d.ts +0 -23
  93. package/dist/context/serializable-query.d.ts +0 -11
  94. package/dist/context/translator.d.ts +0 -4
  95. package/dist/database/database-mappers.d.ts +0 -39
  96. package/dist/database/index.d.ts +0 -3
  97. package/dist/db/index.d.ts +0 -4
  98. package/dist/listener/index.d.ts +0 -2
  99. package/dist/listener/listener.d.ts +0 -23
  100. package/dist/model/EventPublisher.d.ts +0 -12
  101. package/dist/model/event-publisher.d.ts +0 -12
  102. package/dist/query/query-definition.d.ts +0 -8
  103. package/dist/route/index.d.ts +0 -2
  104. package/dist/route/route.d.ts +0 -35
  105. package/dist/rtc/client.d.ts +0 -3
  106. package/dist/rtc/index.d.ts +0 -4
  107. package/dist/rtc/messages.d.ts +0 -20
  108. package/dist/rtc/rtc.d.ts +0 -11
  109. package/dist/server/query-handler.d.ts +0 -43
  110. package/dist/state/index.d.ts +0 -2
  111. package/dist/state/query-builder.d.ts +0 -2
  112. package/dist/state/query.d.ts +0 -2
  113. package/dist/state/state.d.ts +0 -2
  114. package/dist/strategies/cache-strategy.d.ts +0 -20
  115. package/dist/strategies/datastorage-strategy.d.ts +0 -15
  116. package/dist/strategies/index.d.ts +0 -7
  117. package/dist/strategies/leader-strategy.d.ts +0 -16
  118. package/dist/strategies/model-strategy.d.ts +0 -9
  119. package/dist/strategies/query-strategy.d.ts +0 -20
  120. package/dist/telemetry/context.d.ts +0 -65
  121. package/dist/telemetry/index.d.ts +0 -47
  122. package/dist/telemetry/interfaces.d.ts +0 -84
  123. package/dist/telemetry/logger.d.ts +0 -67
  124. package/dist/telemetry/no-op.d.ts +0 -54
  125. package/dist/telemetry/tracer.d.ts +0 -85
  126. package/dist/tests/context/context.test.d.ts +0 -2
  127. package/dist/tests/pipe.d.ts +0 -2
  128. package/dist/tests/query/advance-query.test.d.ts +0 -2
  129. package/dist/tests/query/collection-all.test.d.ts +0 -2
  130. package/dist/tests/utils/expect-not-false.d.ts +0 -2
  131. package/dist/tests/utils/sqlite-adapter.d.ts +0 -3
  132. package/dist/tests/utils/test-model.d.ts +0 -25
  133. package/dist/tests/validations/array.test.d.ts +0 -2
  134. package/dist/tests/validations/date.test.d.ts +0 -2
  135. package/dist/tests/validations/number.test.d.ts +0 -2
  136. package/dist/tests/validations/object.test.d.ts +0 -2
  137. package/dist/tests/validations/record.test.d.ts +0 -2
  138. package/dist/tests/validations/string-enum.test.d.ts +0 -2
  139. package/dist/tests/validations/string.test.d.ts +0 -2
  140. package/dist/utils.d.ts +0 -56
  141. package/dist/view/index.d.ts +0 -6
  142. package/dist/view/queries/abstract-view-query.d.ts +0 -19
  143. package/dist/view/queries/find-one.d.ts +0 -13
  144. package/dist/view/queries/find.d.ts +0 -21
  145. package/dist/view/queries/index.d.ts +0 -3
  146. package/dist/view/query-builders/find-one.d.ts +0 -14
  147. package/dist/view/query-builders/find.d.ts +0 -14
  148. package/dist/view/query-builders/index.d.ts +0 -2
  149. package/dist/view/query-builders/new-query-builder.d.ts +0 -2
  150. package/dist/view/record.d.ts +0 -4
  151. package/dist/view/static-view.d.ts +0 -43
  152. package/dist/view/view.d.ts +0 -68
  153. /package/dist/{database → data-storage}/schema-extraction.d.ts +0 -0
  154. /package/dist/{data-storage → utils}/deep-merge.d.ts +0 -0
@@ -0,0 +1,127 @@
1
+ /**
2
+ * ArcToken - Security context abstraction
3
+ *
4
+ * Tokens carry identity/authorization information across all layers:
5
+ * - React hooks (useCommands)
6
+ * - Commands (protectBy)
7
+ * - Views/Events (protectBy)
8
+ * - DataStorage (secure)
9
+ * - Wire (JWT)
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const moderatorToken = token("moderator", { userId })
14
+ * .secret(process.env.MODERATOR_SECRET)
15
+ * .query([moderatorsView])
16
+ * .withRules({
17
+ * 'form:edit': async (ctx, params) => {
18
+ * return !!await ctx.moderators.findOne({ userId: params.userId });
19
+ * },
20
+ * });
21
+ * ```
22
+ */
23
+ import type { ArcContextElement } from "../context-element/context-element";
24
+ import { ArcObject, type ArcRawShape } from "../elements/object";
25
+ import type { ModelAdapters } from "../model/model-adapters";
26
+ import type { $type } from "../utils/types/get-type";
27
+ import type { ArcTokenData, TokenRules } from "./token-data";
28
+ import { TokenInstance } from "./token-instance";
29
+ export declare class ArcToken<const Name extends string, const ParamsShape extends ArcRawShape, const QueryElements extends ArcContextElement<any>[], const Rules extends TokenRules<$type<ArcObject<ParamsShape>>, QueryElements>> {
30
+ private readonly data;
31
+ constructor(data: ArcTokenData<Name, ParamsShape, QueryElements, Rules>);
32
+ /**
33
+ * Get token name
34
+ */
35
+ get name(): Name;
36
+ /**
37
+ * Get params schema
38
+ */
39
+ get paramsSchema(): ArcObject<ParamsShape>;
40
+ /**
41
+ * Set JWT secret for this token
42
+ * Required for getJWT() and parseJWT()
43
+ *
44
+ * @param secret - Secret key for JWT signing/verification
45
+ */
46
+ secret<const Secret extends string | false | undefined>(secret: Secret): ArcToken<Name, ParamsShape, QueryElements, Rules>;
47
+ /**
48
+ * Add query elements needed for permission checks
49
+ * These views will be available in rule functions
50
+ *
51
+ * @param elements - Array of view elements to query
52
+ */
53
+ query<const Elements extends ArcContextElement<any>[]>(elements: Elements): ArcToken<Name, ParamsShape, Elements, any>;
54
+ /**
55
+ * Define permission rules for this token
56
+ * Rules are async functions that check if permission is granted
57
+ *
58
+ * @param rules - Map of permission names to rule functions
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * .withRules({
63
+ * 'form:edit': async (ctx, params) => {
64
+ * const user = await ctx.users.findOne({ id: params.userId });
65
+ * return user?.role === 'moderator';
66
+ * },
67
+ * })
68
+ * ```
69
+ */
70
+ withRules<const NewRules extends TokenRules<$type<ArcObject<ParamsShape>>, QueryElements>>(rules: NewRules): ArcToken<Name, ParamsShape, QueryElements, NewRules>;
71
+ /**
72
+ * Create a token instance with actual parameter values
73
+ *
74
+ * @param params - Parameter values for this token instance
75
+ * @param adapters - Optional adapters for permission checks
76
+ */
77
+ create(params: $type<ArcObject<ParamsShape>>, adapters?: ModelAdapters): TokenInstance<$type<ArcObject<ParamsShape>>, keyof Rules & string>;
78
+ /**
79
+ * Parse JWT string to create token instance
80
+ *
81
+ * @param jwt - JWT string to parse
82
+ * @param adapters - Optional adapters for permission checks
83
+ * @returns TokenInstance or null if invalid
84
+ */
85
+ parseJWT(jwt: string, adapters?: ModelAdapters): TokenInstance<$type<ArcObject<ParamsShape>>, keyof Rules & string> | null;
86
+ /**
87
+ * Generate JWT string from params
88
+ * Used internally by TokenInstance.getJWT()
89
+ */
90
+ generateJWT(params: $type<ArcObject<ParamsShape>>, expiresIn?: number): string;
91
+ /**
92
+ * Check permission for given params
93
+ * Used internally by TokenInstance.canI()
94
+ */
95
+ checkPermission(permission: string, params: $type<ArcObject<ParamsShape>>, adapters?: ModelAdapters): Promise<boolean>;
96
+ /**
97
+ * Build rule context from query elements
98
+ */
99
+ private buildRuleContext;
100
+ /**
101
+ * Simple HMAC-like signature (for demo purposes)
102
+ * In production, use a proper crypto library
103
+ */
104
+ private sign;
105
+ }
106
+ /**
107
+ * Create a new token definition
108
+ *
109
+ * @param name - Unique token name
110
+ * @param paramsSchema - Schema defining token parameters
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const userToken = token("user", { userId: string() })
115
+ * .secret(process.env.USER_TOKEN_SECRET)
116
+ * .query([usersView])
117
+ * .withRules({
118
+ * 'profile:edit': async (ctx, params) => true,
119
+ * });
120
+ * ```
121
+ */
122
+ export declare function token<const Name extends string, const ParamsShape extends ArcRawShape>(name: Name, paramsSchema: ParamsShape): ArcToken<Name, ParamsShape, [], {}>;
123
+ /**
124
+ * Type alias for any token (used in collections)
125
+ */
126
+ export type ArcTokenAny = ArcToken<any, any, any, any>;
127
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1,4 @@
1
+ export * from "./deep-merge";
2
+ export * from "./murmur-hash";
3
+ export * from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Add question marks to optional properties
3
+ */
4
+ export type AddQuestionMarks<T> = {
5
+ [K in keyof T as undefined extends T[K] ? K : never]?: T[K];
6
+ } & {
7
+ [K in keyof T as undefined extends T[K] ? never : K]: T[K];
8
+ };
9
+ //# sourceMappingURL=add-question-marks.d.ts.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Extract the first argument type from a function
3
+ */
4
+ export type FirstArgument<T extends (...args: any) => any> = T extends (arg: infer A, ...args: any) => any ? A : never;
5
+ //# sourceMappingURL=first-argument.d.ts.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Extract the deserialized type from an element
3
+ */
4
+ export type GetType<E extends {
5
+ deserialize: (...args: any) => any;
6
+ }> = ReturnType<E["deserialize"]>;
7
+ /**
8
+ * Alias for GetType - matches arc-old naming convention
9
+ */
10
+ export type $type<E extends {
11
+ deserialize: (...args: any) => any;
12
+ }> = GetType<E>;
13
+ //# sourceMappingURL=get-type.d.ts.map
@@ -0,0 +1,6 @@
1
+ export type { Merge } from "./merge";
2
+ export type { FirstArgument } from "./first-argument";
3
+ export type { GetType, $type } from "./get-type";
4
+ export type { AddQuestionMarks } from "./add-question-marks";
5
+ export type { Simplify } from "./simplify";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Merge two types, with properties from B overriding properties from A
3
+ */
4
+ export type Merge<A, B> = {
5
+ [K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;
6
+ } & {};
7
+ //# sourceMappingURL=merge.d.ts.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Object utility types - re-exports for namespace usage
3
+ */
4
+ export type { AddQuestionMarks } from "./add-question-marks";
5
+ export type { Simplify as simplify } from "./simplify";
6
+ //# sourceMappingURL=object-util.d.ts.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Simplify a type for better readability in IDE
3
+ */
4
+ export type Simplify<T> = {
5
+ [K in keyof T]: T[K];
6
+ } & {};
7
+ //# sourceMappingURL=simplify.d.ts.map
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc",
3
3
  "type": "module",
4
- "version": "0.1.12",
4
+ "version": "0.3.0",
5
5
  "private": false,
6
6
  "author": "Przemysław Krasiński [arcote.tech]",
7
- "description": "Arc is a framework designed to align code closely with business logic, streamlining development and enhancing productivity.",
7
+ "description": "Arc framework core rewrite with improved event emission and type safety",
8
8
  "main": "./dist/index.js",
9
9
  "module": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
@@ -16,10 +16,12 @@
16
16
  }
17
17
  },
18
18
  "scripts": {
19
- "build": "bun build --target=node ./index.ts --outfile=dist/index.js --external rxjs --external mutative && bun run build:declaration",
20
- "build:declaration": "tsc --emitDeclarationOnly --project tsconfig.types.json --declarationMap",
21
- "postbuild": "rimraf tsconfig.types.tsbuildinfo",
22
- "type-check": "tsc",
19
+ "build": "bun build --target=node ./src/index.ts --outfile=dist/index.js --external rxjs --external mutative && bun run build:declaration",
20
+ "build:declaration": "tsc --emitDeclarationOnly --project tsconfig.json --declarationMap",
21
+ "postbuild": "rimraf tsconfig.tsbuildinfo",
22
+ "type-check": "tsc --noEmit",
23
+ "test": "bun test",
24
+ "test:watch": "bun test --watch",
23
25
  "dev": "nodemon --ignore dist -e ts,tsx --exec 'bun run build'"
24
26
  },
25
27
  "dependencies": {
@@ -27,7 +29,9 @@
27
29
  "rxjs": "^7.8.1"
28
30
  },
29
31
  "devDependencies": {
32
+ "@arcote.tech/arc-old": "workspace:*",
30
33
  "@types/bun": "latest",
34
+ "fast-check": "^3.15.0",
31
35
  "prettier": "^3.0.3",
32
36
  "rimraf": "^5.0.5",
33
37
  "typescript": "^5.2.2",
@@ -1,5 +0,0 @@
1
- export type CommandDefinition = {
2
- readonly commandName: string;
3
- readonly parameters: any;
4
- };
5
- //# sourceMappingURL=command-definition.d.ts.map
@@ -1,45 +0,0 @@
1
- import type { ArcCommandContext } from "../context";
2
- import { ArcContextElement, type ArcContextElementAny } from "../context/element";
3
- import { ArcObject, type ArcObjectAny, type ArcRawShape } from "../elements";
4
- import type { $type } from "../utils";
5
- export type ArcCommmandHandler<ContextElements extends ArcContextElementAny[], Params extends ArcObjectAny | null, Results extends ArcObjectAny[]> = (ctx: ArcCommandContext<ContextElements>, params: Params extends ArcObjectAny ? $type<Params> : null) => Promise<$type<Results[number]>> | $type<Results[number]>;
6
- export declare class ArcCommand<Name extends string, Params extends ArcObjectAny | null, Results extends ArcObjectAny[], const Elements extends ArcContextElementAny[]> extends ArcContextElement<{
7
- type: "execute";
8
- params: Params;
9
- result: Results[number];
10
- }, Name> {
11
- readonly name: Name;
12
- _description?: string;
13
- _params?: Params;
14
- _results?: Results;
15
- _elements?: Elements;
16
- _handler?: ArcCommmandHandler<Elements, Params, Results> | false;
17
- _isPublic: boolean;
18
- constructor(name: Name);
19
- use<const E extends ArcContextElementAny[]>(elements: E): ArcCommand<Name, Params, Results, E>;
20
- description(description: string): ArcCommand<Name, Params, Results, Elements>;
21
- public(): ArcCommand<Name, Params, Results, Elements>;
22
- get isPublic(): boolean;
23
- matchesCommandPath(pathname: string): {
24
- matches: boolean;
25
- isPublic: boolean;
26
- };
27
- withParams<NewParams extends ArcRawShape>(schema: NewParams | ArcObject<NewParams>): ArcCommand<Name, ArcObject<NewParams>, Results, Elements>;
28
- withResult<NewResults extends ArcRawShape[]>(...schemas: NewResults): ArcCommand<Name, Params, { [K in keyof NewResults]: ArcObject<NewResults[K]>; }, Elements>;
29
- handle(handler: ArcCommmandHandler<Elements, Params, Results> | false): ArcCommand<Name, Params, Results, Elements>;
30
- commandClient: (ctx: any) => (Params extends ArcObjectAny ? (params: $type<Params>) => Promise<$type<Results[number]>> : () => Promise<$type<Results[number]>>) & {
31
- params: Params;
32
- };
33
- getUsedElements(): Elements;
34
- protected clone(): ArcCommand<Name, Params, Results, Elements>;
35
- toJsonSchema(): {
36
- type: string;
37
- name: Name;
38
- description: string | undefined;
39
- parameters: any;
40
- strict: boolean;
41
- };
42
- }
43
- export declare function command<Name extends string>(name: Name): ArcCommand<Name, null, any[], any[]>;
44
- export type ArcCommandAny = ArcCommand<any, any, any, any>;
45
- //# sourceMappingURL=command.d.ts.map
@@ -1,2 +0,0 @@
1
- export * from "./command";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { ArcContextAny } from "./context";
2
- export type CommandContext<C extends ArcContextAny> = ReturnType<C["commandContext"]>;
3
- type Command<C extends ArcContextAny> = (context: CommandContext<C>, ...args: any[]) => any;
4
- export type Commands<C extends ArcContextAny> = {
5
- [key: string]: Command<C>;
6
- };
7
- export type CommandProxy<F> = F extends (ctx: any, ...args: infer args) => infer ret ? (...args: args) => ret : never;
8
- export type CommandsClient<Cmds extends Commands<any>> = {
9
- [Key in keyof Cmds]: CommandProxy<Cmds[Key]>;
10
- };
11
- export {};
12
- //# sourceMappingURL=commands.d.ts.map
@@ -1,80 +0,0 @@
1
- import type { DataStorage } from "../data-storage";
2
- import type { WhereCondition } from "../data-storage/types";
3
- import type { QueryBuilderContext } from "./query-builder-context";
4
- export type EventListener<Event> = (event: Event, dataStorage: DataStorage, publishEvent: PublishEventFunction) => Promise<void>;
5
- export type PublishEventFunction = (event: any) => Promise<void>;
6
- export type ListenerConfig = {
7
- handler: EventListener<any>;
8
- isAsync: boolean;
9
- };
10
- export interface AuthContext {
11
- ipAddress?: string;
12
- }
13
- export type AuthorizationRestrictions = {
14
- default?: WhereCondition;
15
- read?: boolean | WhereCondition;
16
- write?: boolean | WhereCondition;
17
- modify?: boolean | WhereCondition;
18
- delete?: boolean | WhereCondition;
19
- };
20
- export type EventAuthorizationRestrictions = {
21
- read?: boolean | WhereCondition;
22
- write?: boolean | WhereCondition;
23
- };
24
- import type { ArcObject } from "../elements/object";
25
- export type StoreColumn = {
26
- name: string;
27
- type: string;
28
- isOptional?: boolean;
29
- default?: any;
30
- computed?: string | ((item: any, context: {
31
- now: string;
32
- }) => any);
33
- };
34
- export type StoreRelation = {
35
- table: string;
36
- type: "one-to-many" | "many-to-many" | "one-to-one";
37
- foreignKey: string;
38
- throughTable?: string;
39
- };
40
- export type StoreTable = {
41
- name: string;
42
- columns: StoreColumn[];
43
- primaryKey: string;
44
- };
45
- export type StoreSchema = {
46
- tables: StoreTable[];
47
- relations?: StoreRelation[];
48
- };
49
- /**
50
- * New database-agnostic schema definition
51
- */
52
- export type DatabaseStoreTable = {
53
- name: string;
54
- schema: ArcObject<any>;
55
- version?: number;
56
- options?: {
57
- /** Include soft delete columns */
58
- softDelete?: boolean;
59
- /** Include per-table version tracking for data syncing */
60
- versioning?: boolean;
61
- };
62
- };
63
- export type DatabaseStoreSchema = {
64
- tables: DatabaseStoreTable[];
65
- relations?: StoreRelation[];
66
- reinitTable?: (tableName: string, dataStorage: DataStorage) => Promise<void>;
67
- };
68
- export declare abstract class ArcContextElement<const Event, const Name extends string | undefined = undefined> {
69
- readonly $event: Event;
70
- readonly name?: Name;
71
- queryBuilder?: (queryContext: QueryBuilderContext, authContext: AuthContext) => any;
72
- commandContext?: (dataStorage: DataStorage, publishEvent: PublishEventFunction, authContext: AuthContext) => any;
73
- commandClient?: (commandContext: any, authContext: AuthContext) => (...args: any[]) => any;
74
- observer?: (authContext: AuthContext) => Record<string, ListenerConfig>;
75
- }
76
- export declare abstract class ArcContextElementWithStore<const Event, const Name extends string | undefined = undefined> extends ArcContextElement<Event, Name> {
77
- abstract databaseStoreSchema(): DatabaseStoreSchema;
78
- }
79
- export type ArcContextElementAny = ArcContextElement<any, any>;
80
- //# sourceMappingURL=element.d.ts.map
@@ -1,45 +0,0 @@
1
- import type { DataStorage } from "../data-storage";
2
- import { ArcObject, type ArcObjectAny, type ArcRawShape } from "../elements/object";
3
- import type { $type } from "../utils";
4
- import { ArcContextElementWithStore, type AuthContext, type AuthorizationRestrictions, type EventAuthorizationRestrictions, type StoreSchema, type DatabaseStoreSchema } from "./element";
5
- export type EventMetadata = {
6
- createdAt: Date;
7
- };
8
- export declare class ArcEvent<const Name extends string, const PayloadShape extends ArcObjectAny | undefined> extends ArcContextElementWithStore<ArcEventInstance<ArcEvent<Name, PayloadShape>>, Name> {
9
- readonly name: Name;
10
- readonly payload: PayloadShape;
11
- private _restrictions?;
12
- storeSchema: () => StoreSchema;
13
- databaseStoreSchema: () => DatabaseStoreSchema;
14
- constructor(name: Name, payload: PayloadShape);
15
- /**
16
- * Default restrictions for events - deny all operations except for system users
17
- * Override using the auth() method to customize authorization
18
- */
19
- restrictions(authContext: AuthContext): AuthorizationRestrictions;
20
- /**
21
- * Define custom authorization restrictions for this event (read and write only)
22
- * @param restrictionsFn - Function that takes auth context and returns read/write restrictions
23
- */
24
- auth(restrictionsFn: (authContext: AuthContext) => EventAuthorizationRestrictions): ArcEvent<Name, PayloadShape>;
25
- commandContext: (dataStorage: DataStorage, publishEvent: (event: ArcEventInstance<ArcEvent<Name, PayloadShape>>) => Promise<void>) => {
26
- emit: (payload: PayloadShape extends ArcObjectAny ? $type<PayloadShape> : undefined) => Promise<void>;
27
- };
28
- }
29
- export type ArcEventInstance<Event extends ArcEventAny> = {
30
- type: Event["name"];
31
- payload: Event["payload"] extends ArcObjectAny ? $type<Event["payload"]> : undefined;
32
- } & EventMetadata;
33
- export type ArcEventAny = ArcEvent<any, any>;
34
- export type ArcEventPayload<Event extends ArcEventAny> = Event extends ArcEvent<any, infer PayloadShape extends ArcObjectAny> ? $type<PayloadShape> : undefined;
35
- export declare function event<const Name extends string, PayloadShape extends ArcObjectAny | ArcRawShape | undefined>(name: Name, payload?: PayloadShape): ArcEvent<Name, PayloadShape extends ArcRawShape ? ArcObject<PayloadShape, [{
36
- name: "type";
37
- validator: (value: any) => false | {
38
- current: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
39
- expected: "object";
40
- };
41
- }, {
42
- name: "schema";
43
- validator: (value: any) => false | { [key in keyof PayloadShape]: ReturnType<PayloadShape[key]["validate"]>; };
44
- }]> : PayloadShape extends ArcObjectAny ? PayloadShape : undefined>;
45
- //# sourceMappingURL=event.d.ts.map
@@ -1,15 +0,0 @@
1
- import type { DataStorage } from "../data-storage/data-storage.abstract";
2
- import type { ArcQueryAny } from "./query";
3
- import { QueryCache } from "./query-cache";
4
- export declare class QueryBuilderContext {
5
- private readonly queryCache;
6
- private readonly dataStorage;
7
- private usedQueries;
8
- constructor(queryCache: QueryCache, dataStorage: DataStorage);
9
- cacheQuery<T extends ArcQueryAny, Arguments extends any[]>(QueryConstructor: (new (...args: Arguments) => T) & {
10
- key: string;
11
- }, args: Arguments): T;
12
- runQuery<T extends ArcQueryAny>(query: T): T["lastResult"];
13
- getUsedQueries(): ArcQueryAny[];
14
- }
15
- //# sourceMappingURL=query-builder-context.d.ts.map
@@ -1,17 +0,0 @@
1
- import type { ArcContextAny } from "./context";
2
- import type { ArcQueryAny } from "./query";
3
- import type { QueryBuilderContext } from "./query-builder-context";
4
- export type RunQuery<T extends ArcQueryAny> = (query: T) => T["lastResult"];
5
- export interface IArcQueryBuilder {
6
- toQuery(context?: QueryBuilderContext): ArcQueryAny;
7
- }
8
- export declare abstract class ArcQueryBuilder implements IArcQueryBuilder {
9
- protected queryContext: QueryBuilderContext;
10
- constructor(queryContext: QueryBuilderContext);
11
- abstract toQuery(): ArcQueryAny;
12
- run(): ReturnType<this["toQuery"]>["lastResult"];
13
- }
14
- export type UnaryFunction<T, R> = (input: T) => R;
15
- export type QueryFactoryFunction<C extends ArcContextAny> = UnaryFunction<ReturnType<C["queryBuilder"]>, IArcQueryBuilder>;
16
- export type QueryBuilderFunctionResult<QueryBuilderFn extends QueryFactoryFunction<any>> = QueryBuilderFn extends QueryFactoryFunction<infer C> ? Promise<ReturnType<ReturnType<QueryBuilderFn>["toQuery"]>["lastResult"]> : never;
17
- //# sourceMappingURL=query-builders.d.ts.map
@@ -1,9 +0,0 @@
1
- import type { ArcQueryAny } from "./query";
2
- export declare class QueryCache {
3
- private cache;
4
- private getIndexHash;
5
- set(index: any[], query: ArcQueryAny): void;
6
- get(index: any[]): ArcQueryAny | undefined;
7
- debug(): Map<any, any>;
8
- }
9
- //# sourceMappingURL=query-cache.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { DataStorage } from "../data-storage";
2
- export type ArcQueryListener<Result> = (result: Result) => void;
3
- export declare abstract class ArcQuery<Result> {
4
- lastResult: Result;
5
- abstract run(dataStorage: DataStorage): Promise<Result>;
6
- private listeners;
7
- subscribe(listener: ArcQueryListener<Result>): void;
8
- unsubscribe(listener: ArcQueryListener<Result>): void;
9
- nextResult(result: Result): void;
10
- }
11
- export type ArcQueryAny = ArcQuery<any>;
12
- //# sourceMappingURL=query.d.ts.map
@@ -1,23 +0,0 @@
1
- import { ArcQuery } from "./query";
2
- import type { QueryBuilderContext } from "./query-builder-context";
3
- import { type IArcQueryBuilder, type UnaryFunction } from "./query-builders";
4
- declare class ReactiveQuery<T, R> extends ArcQuery<Awaited<R>> {
5
- private readonly queryContext;
6
- private readonly queryBuilder;
7
- private readonly fn;
8
- queries: ArcQuery<any>[];
9
- constructor(queryContext: QueryBuilderContext, queryBuilder: T, fn: UnaryFunction<T, R>);
10
- run(): Promise<Awaited<R>>;
11
- private onChangeHandler;
12
- onChange(): Promise<void>;
13
- runQuery(): Promise<R>;
14
- }
15
- declare class ReactiveQueryBuilder<T, R> implements IArcQueryBuilder {
16
- private readonly queryBuilder;
17
- private readonly fn;
18
- constructor(queryBuilder: T, fn: UnaryFunction<T, R>);
19
- toQuery(context: QueryBuilderContext): ReactiveQuery<T, R>;
20
- }
21
- export declare function reactive<T, R>(fn: UnaryFunction<T, R>): (context: T) => ReactiveQueryBuilder<T, R>;
22
- export {};
23
- //# sourceMappingURL=reactive-query.d.ts.map
@@ -1,11 +0,0 @@
1
- import { ArcQuery } from "./query";
2
- export declare abstract class ArcSerializableQuery<Result, Params> extends ArcQuery<Result> {
3
- protected readonly params: Params;
4
- static key: string;
5
- constructor(params: Params);
6
- serialize(): {
7
- key: any;
8
- params: Params;
9
- };
10
- }
11
- //# sourceMappingURL=serializable-query.d.ts.map
@@ -1,4 +0,0 @@
1
- import type { ArcEventAny, ArcEventInstance, ArcEventPayload } from "./event";
2
- export type Translation<From extends ArcEventAny, To extends ArcEventAny> = (event: ArcEventInstance<From>) => ArcEventPayload<To>;
3
- export declare function translate<From extends ArcEventAny, To extends ArcEventAny>(from: From, to: To, translation: Translation<From, To>): import("..").ArcListener<`${From["name"]}To${To["name"]}Translator`, [To], [From]>;
4
- //# sourceMappingURL=translator.d.ts.map
@@ -1,39 +0,0 @@
1
- import type { DatabaseType, DatabaseTypeMapper, DatabaseFeatures, DatabaseStoreData, DatabaseColumnDefinition } from "./database-store";
2
- /**
3
- * SQLite Type Mapper
4
- */
5
- export declare class SQLiteTypeMapper implements DatabaseTypeMapper {
6
- databaseType: DatabaseType;
7
- features: DatabaseFeatures;
8
- mapType(arcTypeName: string, storeData?: DatabaseStoreData): string;
9
- mapConstraints(storeData: DatabaseStoreData): string[];
10
- generateColumnDefinition(column: DatabaseColumnDefinition): string;
11
- generateCreateTableSQL(tableName: string, columns: DatabaseColumnDefinition[]): string;
12
- }
13
- /**
14
- * PostgreSQL Type Mapper
15
- */
16
- export declare class PostgreSQLTypeMapper implements DatabaseTypeMapper {
17
- databaseType: DatabaseType;
18
- features: DatabaseFeatures;
19
- mapType(arcTypeName: string, storeData?: DatabaseStoreData): string;
20
- mapConstraints(storeData: DatabaseStoreData): string[];
21
- generateColumnDefinition(column: DatabaseColumnDefinition): string;
22
- generateCreateTableSQL(tableName: string, columns: DatabaseColumnDefinition[]): string;
23
- }
24
- /**
25
- * MySQL Type Mapper
26
- */
27
- export declare class MySQLTypeMapper implements DatabaseTypeMapper {
28
- databaseType: DatabaseType;
29
- features: DatabaseFeatures;
30
- mapType(arcTypeName: string, storeData?: DatabaseStoreData): string;
31
- mapConstraints(storeData: DatabaseStoreData): string[];
32
- generateColumnDefinition(column: DatabaseColumnDefinition): string;
33
- generateCreateTableSQL(tableName: string, columns: DatabaseColumnDefinition[]): string;
34
- }
35
- /**
36
- * Database Type Mapper Factory
37
- */
38
- export declare function createDatabaseTypeMapper(databaseType: DatabaseType): DatabaseTypeMapper;
39
- //# sourceMappingURL=database-mappers.d.ts.map
@@ -1,3 +0,0 @@
1
- export * from "./database-store";
2
- export * from "./schema-extraction";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,4 +0,0 @@
1
- export * from "./interface";
2
- export * from "./postgresAdapter";
3
- export * from "./sqliteAdapter";
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +0,0 @@
1
- export * from "./listener";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,23 +0,0 @@
1
- import { type ArcCommandContext, type AuthContext } from "../context";
2
- import { ArcContextElement, type ArcContextElementAny, type ListenerConfig } from "../context/element";
3
- type GetEvents<Elements extends ArcContextElementAny[]> = Elements[number]["$event"];
4
- export type ArcListenerHandler<ContextElements extends ArcContextElementAny[], EventElements extends ArcContextElementAny[]> = (ctx: ArcCommandContext<ContextElements>, event: GetEvents<EventElements>) => Promise<void> | void;
5
- export declare class ArcListener<Name extends string, const Elements extends ArcContextElementAny[], EventElements extends ArcContextElementAny[] = ArcContextElementAny[]> extends ArcContextElement<null, Name> {
6
- readonly name: Name;
7
- private _description?;
8
- private _elements?;
9
- private _eventElements?;
10
- private _handler?;
11
- private _isAsync;
12
- constructor(name: Name);
13
- use<const E extends ArcContextElementAny[]>(elements: E): ArcListener<Name, E, EventElements>;
14
- description(description: string): ArcListener<Name, Elements, EventElements>;
15
- listenTo<const E extends ArcContextElementAny[]>(events: E): ArcListener<Name, Elements, E>;
16
- async(): ArcListener<Name, Elements, EventElements>;
17
- handle(handler: ArcListenerHandler<Elements, EventElements>): ArcListener<Name, Elements, EventElements>;
18
- observer: (authContext: AuthContext) => Record<string, ListenerConfig>;
19
- private clone;
20
- }
21
- export declare function listener<Name extends string>(name: Name): ArcListener<Name, any[], any[]>;
22
- export {};
23
- //# sourceMappingURL=listener.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { ArcContextAny, AuthContext } from "../context";
2
- import type { DataStorage } from "../data-storage";
3
- export declare class EventPublisher<C extends ArcContextAny> {
4
- private readonly context;
5
- private readonly dataStorage;
6
- private readonly authContext;
7
- private asyncEvents;
8
- constructor(context: C, dataStorage: DataStorage, authContext: AuthContext);
9
- publishEvent(event: any, commandDataStorage: DataStorage): Promise<void>;
10
- runAsyncListeners(): Promise<void>;
11
- }
12
- //# sourceMappingURL=EventPublisher.d.ts.map
@@ -1,12 +0,0 @@
1
- import type { ArcContextAny, AuthContext } from "../context";
2
- import type { DataStorage } from "../data-storage";
3
- export declare class EventPublisher<C extends ArcContextAny> {
4
- private readonly context;
5
- private readonly dataStorage;
6
- private readonly authContext;
7
- private asyncEvents;
8
- constructor(context: C, dataStorage: DataStorage, authContext: AuthContext);
9
- publishEvent(event: any, commandDataStorage: DataStorage): Promise<void>;
10
- runAsyncListeners(): Promise<void>;
11
- }
12
- //# sourceMappingURL=event-publisher.d.ts.map