@dxos/functions 0.8.2-main.12df754 → 0.8.2-main.2f9c567

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 (168) hide show
  1. package/dist/lib/browser/bundler/index.mjs +0 -3
  2. package/dist/lib/browser/bundler/index.mjs.map +1 -1
  3. package/dist/lib/browser/edge/index.mjs +63 -7
  4. package/dist/lib/browser/edge/index.mjs.map +4 -4
  5. package/dist/lib/browser/index.mjs +367 -99
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/node/bundler/index.cjs +0 -1
  9. package/dist/lib/node/bundler/index.cjs.map +1 -1
  10. package/dist/lib/node/edge/index.cjs +65 -5
  11. package/dist/lib/node/edge/index.cjs.map +4 -4
  12. package/dist/lib/node/index.cjs +382 -94
  13. package/dist/lib/node/index.cjs.map +4 -4
  14. package/dist/lib/node/meta.json +1 -1
  15. package/dist/lib/node-esm/bundler/index.mjs +0 -1
  16. package/dist/lib/node-esm/bundler/index.mjs.map +1 -1
  17. package/dist/lib/node-esm/edge/index.mjs +64 -6
  18. package/dist/lib/node-esm/edge/index.mjs.map +4 -4
  19. package/dist/lib/node-esm/index.mjs +367 -97
  20. package/dist/lib/node-esm/index.mjs.map +4 -4
  21. package/dist/lib/node-esm/meta.json +1 -1
  22. package/dist/types/src/edge/index.d.ts.map +1 -1
  23. package/dist/types/src/handler.d.ts +12 -61
  24. package/dist/types/src/handler.d.ts.map +1 -1
  25. package/dist/types/src/index.d.ts +3 -3
  26. package/dist/types/src/index.d.ts.map +1 -1
  27. package/dist/types/src/schema.d.ts +57 -0
  28. package/dist/types/src/schema.d.ts.map +1 -0
  29. package/dist/types/src/trace.d.ts +148 -0
  30. package/dist/types/src/trace.d.ts.map +1 -0
  31. package/dist/types/src/{types/types.d.ts → types.d.ts} +191 -49
  32. package/dist/types/src/types.d.ts.map +1 -0
  33. package/dist/types/src/url.d.ts.map +1 -0
  34. package/package.json +20 -36
  35. package/src/edge/index.ts +4 -0
  36. package/src/handler.ts +14 -118
  37. package/src/index.ts +4 -5
  38. package/src/schema.ts +53 -0
  39. package/src/{types/trace.ts → trace.ts} +33 -31
  40. package/src/translations.ts +1 -1
  41. package/src/types.ts +214 -0
  42. package/dist/lib/browser/chunk-2YE6S7XY.mjs +0 -360
  43. package/dist/lib/browser/chunk-2YE6S7XY.mjs.map +0 -7
  44. package/dist/lib/browser/chunk-7CHDHCV3.mjs +0 -482
  45. package/dist/lib/browser/chunk-7CHDHCV3.mjs.map +0 -7
  46. package/dist/lib/browser/chunk-LT4LR4VU.mjs +0 -72
  47. package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +0 -7
  48. package/dist/lib/browser/chunk-XRCXIG74.mjs +0 -12
  49. package/dist/lib/browser/chunk-XRCXIG74.mjs.map +0 -7
  50. package/dist/lib/browser/testing/index.mjs +0 -670
  51. package/dist/lib/browser/testing/index.mjs.map +0 -7
  52. package/dist/lib/browser/types/index.mjs +0 -51
  53. package/dist/lib/browser/types/index.mjs.map +0 -7
  54. package/dist/lib/node/chunk-FBIUZ7SD.cjs +0 -496
  55. package/dist/lib/node/chunk-FBIUZ7SD.cjs.map +0 -7
  56. package/dist/lib/node/chunk-JEQ2X3Z6.cjs +0 -34
  57. package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +0 -7
  58. package/dist/lib/node/chunk-NXZNXVT3.cjs +0 -94
  59. package/dist/lib/node/chunk-NXZNXVT3.cjs.map +0 -7
  60. package/dist/lib/node/chunk-SV5NRE5L.cjs +0 -395
  61. package/dist/lib/node/chunk-SV5NRE5L.cjs.map +0 -7
  62. package/dist/lib/node/testing/index.cjs +0 -687
  63. package/dist/lib/node/testing/index.cjs.map +0 -7
  64. package/dist/lib/node/types/index.cjs +0 -72
  65. package/dist/lib/node/types/index.cjs.map +0 -7
  66. package/dist/lib/node-esm/chunk-3XMJFSID.mjs +0 -360
  67. package/dist/lib/node-esm/chunk-3XMJFSID.mjs.map +0 -7
  68. package/dist/lib/node-esm/chunk-C6YINTWG.mjs +0 -482
  69. package/dist/lib/node-esm/chunk-C6YINTWG.mjs.map +0 -7
  70. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +0 -12
  71. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +0 -7
  72. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs +0 -72
  73. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +0 -7
  74. package/dist/lib/node-esm/testing/index.mjs +0 -670
  75. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  76. package/dist/lib/node-esm/types/index.mjs +0 -51
  77. package/dist/lib/node-esm/types/index.mjs.map +0 -7
  78. package/dist/types/src/browser/index.d.ts +0 -2
  79. package/dist/types/src/browser/index.d.ts.map +0 -1
  80. package/dist/types/src/function/function-registry.d.ts +0 -25
  81. package/dist/types/src/function/function-registry.d.ts.map +0 -1
  82. package/dist/types/src/function/function-registry.test.d.ts +0 -2
  83. package/dist/types/src/function/function-registry.test.d.ts.map +0 -1
  84. package/dist/types/src/function/index.d.ts +0 -2
  85. package/dist/types/src/function/index.d.ts.map +0 -1
  86. package/dist/types/src/runtime/dev-server.d.ts +0 -52
  87. package/dist/types/src/runtime/dev-server.d.ts.map +0 -1
  88. package/dist/types/src/runtime/dev-server.test.d.ts +0 -2
  89. package/dist/types/src/runtime/dev-server.test.d.ts.map +0 -1
  90. package/dist/types/src/runtime/index.d.ts +0 -3
  91. package/dist/types/src/runtime/index.d.ts.map +0 -1
  92. package/dist/types/src/runtime/scheduler.d.ts +0 -34
  93. package/dist/types/src/runtime/scheduler.d.ts.map +0 -1
  94. package/dist/types/src/runtime/scheduler.test.d.ts +0 -2
  95. package/dist/types/src/runtime/scheduler.test.d.ts.map +0 -1
  96. package/dist/types/src/testing/functions-integration.test.d.ts +0 -2
  97. package/dist/types/src/testing/functions-integration.test.d.ts.map +0 -1
  98. package/dist/types/src/testing/index.d.ts +0 -5
  99. package/dist/types/src/testing/index.d.ts.map +0 -1
  100. package/dist/types/src/testing/manifest.d.ts +0 -3
  101. package/dist/types/src/testing/manifest.d.ts.map +0 -1
  102. package/dist/types/src/testing/plugin-init.d.ts +0 -6
  103. package/dist/types/src/testing/plugin-init.d.ts.map +0 -1
  104. package/dist/types/src/testing/setup.d.ts +0 -15
  105. package/dist/types/src/testing/setup.d.ts.map +0 -1
  106. package/dist/types/src/testing/test/handler.d.ts +0 -4
  107. package/dist/types/src/testing/test/handler.d.ts.map +0 -1
  108. package/dist/types/src/testing/test/index.d.ts +0 -3
  109. package/dist/types/src/testing/test/index.d.ts.map +0 -1
  110. package/dist/types/src/testing/types.d.ts +0 -10
  111. package/dist/types/src/testing/types.d.ts.map +0 -1
  112. package/dist/types/src/testing/util.d.ts +0 -5
  113. package/dist/types/src/testing/util.d.ts.map +0 -1
  114. package/dist/types/src/trigger/index.d.ts +0 -3
  115. package/dist/types/src/trigger/index.d.ts.map +0 -1
  116. package/dist/types/src/trigger/trigger-registry.d.ts +0 -38
  117. package/dist/types/src/trigger/trigger-registry.d.ts.map +0 -1
  118. package/dist/types/src/trigger/trigger-registry.test.d.ts +0 -2
  119. package/dist/types/src/trigger/trigger-registry.test.d.ts.map +0 -1
  120. package/dist/types/src/trigger/type/index.d.ts +0 -3
  121. package/dist/types/src/trigger/type/index.d.ts.map +0 -1
  122. package/dist/types/src/trigger/type/subscription-trigger.d.ts +0 -4
  123. package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +0 -1
  124. package/dist/types/src/trigger/type/timer-trigger.d.ts +0 -4
  125. package/dist/types/src/trigger/type/timer-trigger.d.ts.map +0 -1
  126. package/dist/types/src/trigger/type/webhook-trigger.d.ts +0 -4
  127. package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +0 -1
  128. package/dist/types/src/types/index.d.ts +0 -5
  129. package/dist/types/src/types/index.d.ts.map +0 -1
  130. package/dist/types/src/types/schema.d.ts +0 -53
  131. package/dist/types/src/types/schema.d.ts.map +0 -1
  132. package/dist/types/src/types/trace.d.ts +0 -146
  133. package/dist/types/src/types/trace.d.ts.map +0 -1
  134. package/dist/types/src/types/types.d.ts.map +0 -1
  135. package/dist/types/src/types/url.d.ts.map +0 -1
  136. package/dist/types/tools/schema.d.ts +0 -2
  137. package/dist/types/tools/schema.d.ts.map +0 -1
  138. package/schema/functions.json +0 -211
  139. package/src/browser/index.ts +0 -5
  140. package/src/function/function-registry.test.ts +0 -118
  141. package/src/function/function-registry.ts +0 -104
  142. package/src/function/index.ts +0 -5
  143. package/src/runtime/dev-server.test.ts +0 -79
  144. package/src/runtime/dev-server.ts +0 -240
  145. package/src/runtime/index.ts +0 -6
  146. package/src/runtime/scheduler.test.ts +0 -152
  147. package/src/runtime/scheduler.ts +0 -170
  148. package/src/testing/functions-integration.test.ts +0 -65
  149. package/src/testing/index.ts +0 -8
  150. package/src/testing/manifest.ts +0 -15
  151. package/src/testing/plugin-init.ts +0 -20
  152. package/src/testing/setup.ts +0 -109
  153. package/src/testing/test/handler.ts +0 -15
  154. package/src/testing/test/index.ts +0 -7
  155. package/src/testing/types.ts +0 -9
  156. package/src/testing/util.ts +0 -26
  157. package/src/trigger/index.ts +0 -6
  158. package/src/trigger/trigger-registry.test.ts +0 -278
  159. package/src/trigger/trigger-registry.ts +0 -218
  160. package/src/trigger/type/index.ts +0 -7
  161. package/src/trigger/type/subscription-trigger.ts +0 -84
  162. package/src/trigger/type/timer-trigger.ts +0 -48
  163. package/src/trigger/type/webhook-trigger.ts +0 -48
  164. package/src/types/index.ts +0 -8
  165. package/src/types/schema.ts +0 -46
  166. package/src/types/types.ts +0 -163
  167. /package/dist/types/src/{types/url.d.ts → url.d.ts} +0 -0
  168. /package/src/{types/url.ts → url.ts} +0 -0
@@ -1,146 +0,0 @@
1
- import { Expando, Ref, S } from '@dxos/echo-schema';
2
- import { type FunctionTriggerType } from './types';
3
- export declare enum InvocationOutcome {
4
- SUCCESS = "success",
5
- FAILURE = "failure",
6
- PENDING = "pending"
7
- }
8
- export declare enum InvocationTraceEventType {
9
- START = "start",
10
- END = "end"
11
- }
12
- export declare const TraceEventException: S.Struct<{
13
- timestampMs: typeof S.Number;
14
- message: typeof S.String;
15
- name: typeof S.String;
16
- stack: S.optional<typeof S.String>;
17
- }>;
18
- export type TraceEventException = S.Schema.Type<typeof TraceEventException>;
19
- export declare const InvocationTraceStartEvent: import("@dxos/echo-schema").EchoObjectSchema<S.Struct<{
20
- /**
21
- * Queue message id.
22
- */
23
- id: import("@dxos/echo-schema").ObjectIdClass;
24
- type: S.Literal<[InvocationTraceEventType.START]>;
25
- /**
26
- * Invocation id, the same for invocation start and end events.
27
- */
28
- invocationId: import("@dxos/echo-schema").ObjectIdClass;
29
- /**
30
- * Event generation time.
31
- */
32
- timestampMs: typeof S.Number;
33
- /**
34
- * Data passed to function / workflow as an argument.
35
- */
36
- input: typeof S.Object;
37
- /**
38
- * Queue DXN for function/workflow invocation events.
39
- */
40
- invocationTraceQueue: import("@dxos/echo-schema").Ref$<Expando>;
41
- /**
42
- * DXN of the invoked function/workflow.
43
- */
44
- invocationTarget: import("@dxos/echo-schema").Ref$<Expando>;
45
- /**
46
- * Present for automatic invocations.
47
- */
48
- trigger: S.optional<import("@dxos/echo-schema").Ref$<import("@dxos/echo-schema").TypedObjectFields<{
49
- readonly function: S.optional<S.SchemaClass<string, string, never>>;
50
- readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
51
- readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
52
- type: S.Literal<[import("./types").TriggerKind.Timer]>;
53
- cron: S.SchemaClass<string, string, never>;
54
- }>>, S.mutable<S.Struct<{
55
- type: S.Literal<[import("./types").TriggerKind.Webhook]>;
56
- method: S.optional<S.SchemaClass<string, string, never>>;
57
- port: S.optional<S.SchemaClass<number, number, never>>;
58
- }>>, S.mutable<S.Struct<{
59
- type: S.Literal<[import("./types").TriggerKind.Subscription]>;
60
- filter: S.Struct<{
61
- type: S.optional<S.SchemaClass<string, string, never>>;
62
- props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
63
- }>;
64
- options: S.optional<S.Struct<{
65
- deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
66
- delay: S.optional<S.SchemaClass<number, number, never>>;
67
- }>>;
68
- }>>, S.mutable<S.Struct<{
69
- type: S.Literal<[import("./types").TriggerKind.Email]>;
70
- }>>, S.mutable<S.Struct<{
71
- type: S.Literal<[import("./types").TriggerKind.Queue]>;
72
- queue: S.refine<string, typeof S.NonEmptyString>;
73
- }>>]>>;
74
- readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
75
- }, import("@dxos/echo-schema").TypedObjectOptions>>>;
76
- }>>;
77
- export type InvocationTraceStartEvent = S.Schema.Type<typeof InvocationTraceStartEvent>;
78
- export declare const InvocationTraceEndEvent: import("@dxos/echo-schema").EchoObjectSchema<S.Struct<{
79
- /**
80
- * Trace event id.
81
- */
82
- id: import("@dxos/echo-schema").ObjectIdClass;
83
- type: S.Literal<[InvocationTraceEventType.END]>;
84
- /**
85
- * Invocation id, will be the same for invocation start and end.
86
- */
87
- invocationId: import("@dxos/echo-schema").ObjectIdClass;
88
- /**
89
- * Event generation time.
90
- */
91
- timestampMs: typeof S.Number;
92
- outcome: S.Enums<typeof InvocationOutcome>;
93
- exception: S.optional<S.Struct<{
94
- timestampMs: typeof S.Number;
95
- message: typeof S.String;
96
- name: typeof S.String;
97
- stack: S.optional<typeof S.String>;
98
- }>>;
99
- }>>;
100
- export type InvocationTraceEndEvent = S.Schema.Type<typeof InvocationTraceEndEvent>;
101
- export type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;
102
- export declare const TraceEventLog: S.Struct<{
103
- timestampMs: typeof S.Number;
104
- level: typeof S.String;
105
- message: typeof S.String;
106
- context: S.optional<typeof S.Object>;
107
- }>;
108
- export declare const TraceEvent: import("@dxos/echo-schema").EchoObjectSchema<S.Struct<{
109
- id: import("@dxos/echo-schema").ObjectIdClass;
110
- outcome: typeof S.String;
111
- truncated: typeof S.Boolean;
112
- /**
113
- * Time when the event was persisted.
114
- */
115
- ingestionTimestampMs: typeof S.Number;
116
- logs: S.Array$<S.Struct<{
117
- timestampMs: typeof S.Number;
118
- level: typeof S.String;
119
- message: typeof S.String;
120
- context: S.optional<typeof S.Object>;
121
- }>>;
122
- exceptions: S.Array$<S.Struct<{
123
- timestampMs: typeof S.Number;
124
- message: typeof S.String;
125
- name: typeof S.String;
126
- stack: S.optional<typeof S.String>;
127
- }>>;
128
- }>>;
129
- export type TraceEvent = S.Schema.Type<typeof TraceEvent>;
130
- /**
131
- * Deprecated InvocationTrace event format.
132
- * @deprecated
133
- */
134
- export type InvocationSpan = {
135
- id: string;
136
- timestampMs: number;
137
- outcome: InvocationOutcome;
138
- input: object;
139
- durationMs: number;
140
- invocationTraceQueue: Ref<Expando>;
141
- invocationTarget: Ref<Expando>;
142
- trigger?: Ref<FunctionTriggerType>;
143
- exception?: TraceEventException;
144
- };
145
- export declare const createInvocationSpans: (items?: InvocationTraceEvent[]) => InvocationSpan[];
146
- //# sourceMappingURL=trace.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../../../src/types/trace.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,OAAO,EAAY,GAAG,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEpE,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAGD,oBAAY,wBAAwB;IAClC,KAAK,UAAU;IACf,GAAG,QAAQ;CACZ;AAED,eAAO,MAAM,mBAAmB;;;;;EAK9B,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE5E,eAAO,MAAM,yBAAyB;IACpC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
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../tools/schema.ts"],"names":[],"mappings":""}
@@ -1,211 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
3
- "type": "object",
4
- "required": [],
5
- "properties": {
6
- "functions": {
7
- "type": "array",
8
- "items": {
9
- "type": "object",
10
- "required": [
11
- "uri",
12
- "route",
13
- "handler"
14
- ],
15
- "properties": {
16
- "uri": {
17
- "type": "string",
18
- "description": "a string",
19
- "title": "string"
20
- },
21
- "route": {
22
- "type": "string",
23
- "description": "a string",
24
- "title": "string"
25
- },
26
- "handler": {
27
- "type": "string",
28
- "description": "a string",
29
- "title": "string"
30
- },
31
- "description": {
32
- "type": "string",
33
- "description": "a string",
34
- "title": "string"
35
- }
36
- },
37
- "additionalProperties": false
38
- }
39
- },
40
- "triggers": {
41
- "type": "array",
42
- "items": {
43
- "type": "object",
44
- "required": [
45
- "function",
46
- "spec"
47
- ],
48
- "properties": {
49
- "function": {
50
- "type": "string",
51
- "description": "Function",
52
- "title": "string"
53
- },
54
- "enabled": {
55
- "type": "boolean",
56
- "description": "a boolean",
57
- "title": "boolean"
58
- },
59
- "meta": {
60
- "$ref": "#/$defs/object"
61
- },
62
- "spec": {
63
- "anyOf": [
64
- {
65
- "type": "object",
66
- "required": [
67
- "type",
68
- "cron"
69
- ],
70
- "properties": {
71
- "type": {
72
- "const": "timer"
73
- },
74
- "cron": {
75
- "type": "string",
76
- "description": "a string",
77
- "title": "string"
78
- }
79
- },
80
- "additionalProperties": false
81
- },
82
- {
83
- "type": "object",
84
- "required": [
85
- "type",
86
- "method"
87
- ],
88
- "properties": {
89
- "type": {
90
- "const": "webhook"
91
- },
92
- "method": {
93
- "type": "string",
94
- "description": "a string",
95
- "title": "string"
96
- },
97
- "port": {
98
- "type": "number",
99
- "description": "a number",
100
- "title": "number"
101
- }
102
- },
103
- "additionalProperties": false
104
- },
105
- {
106
- "type": "object",
107
- "required": [
108
- "type",
109
- "url"
110
- ],
111
- "properties": {
112
- "type": {
113
- "const": "websocket"
114
- },
115
- "url": {
116
- "type": "string",
117
- "description": "a string",
118
- "title": "string"
119
- },
120
- "init": {
121
- "type": "object",
122
- "required": [],
123
- "properties": {},
124
- "additionalProperties": {
125
- "$id": "/schemas/any",
126
- "title": "any"
127
- }
128
- }
129
- },
130
- "additionalProperties": false
131
- },
132
- {
133
- "type": "object",
134
- "required": [
135
- "type",
136
- "filter"
137
- ],
138
- "properties": {
139
- "type": {
140
- "const": "subscription"
141
- },
142
- "filter": {
143
- "type": "array",
144
- "items": {
145
- "type": "object",
146
- "required": [
147
- "type"
148
- ],
149
- "properties": {
150
- "type": {
151
- "type": "string",
152
- "description": "a string",
153
- "title": "string"
154
- },
155
- "props": {
156
- "type": "object",
157
- "required": [],
158
- "properties": {},
159
- "additionalProperties": {
160
- "$id": "/schemas/any",
161
- "title": "any"
162
- }
163
- }
164
- },
165
- "additionalProperties": false
166
- }
167
- },
168
- "options": {
169
- "type": "object",
170
- "required": [],
171
- "properties": {
172
- "deep": {
173
- "type": "boolean",
174
- "description": "a boolean",
175
- "title": "boolean"
176
- },
177
- "delay": {
178
- "type": "number",
179
- "description": "a number",
180
- "title": "number"
181
- }
182
- },
183
- "additionalProperties": false
184
- }
185
- },
186
- "additionalProperties": false
187
- }
188
- ]
189
- }
190
- },
191
- "additionalProperties": false
192
- }
193
- }
194
- },
195
- "additionalProperties": false,
196
- "$defs": {
197
- "object": {
198
- "$id": "/schemas/object",
199
- "oneOf": [
200
- {
201
- "type": "object"
202
- },
203
- {
204
- "type": "array"
205
- }
206
- ],
207
- "description": "an object in the TypeScript meaning, i.e. the `object` type",
208
- "title": "object"
209
- }
210
- }
211
- }
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from '../types';
@@ -1,118 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { afterEach, beforeEach, describe, expect, test } from 'vitest';
6
-
7
- import { Trigger } from '@dxos/async';
8
- import { type Client } from '@dxos/client';
9
- import { TestBuilder } from '@dxos/client/testing';
10
- import { Context } from '@dxos/context';
11
- import { Filter } from '@dxos/echo-db';
12
- import { live } from '@dxos/live-object';
13
- import { range } from '@dxos/util';
14
-
15
- import { FunctionRegistry } from './function-registry';
16
- import { createInitializedClients } from '../testing';
17
- import { FunctionDef, type FunctionManifest } from '../types';
18
-
19
- const testManifest: FunctionManifest = {
20
- functions: [
21
- {
22
- uri: 'dxos.functions.test/hello',
23
- route: '/hello',
24
- handler: 'test',
25
- },
26
- ],
27
- };
28
-
29
- describe('function registry', () => {
30
- let ctx: Context;
31
- let testBuilder: TestBuilder;
32
-
33
- beforeEach(async () => {
34
- ctx = new Context();
35
- testBuilder = new TestBuilder();
36
- });
37
-
38
- afterEach(async () => {
39
- await ctx.dispose();
40
- await testBuilder.destroy();
41
- });
42
-
43
- test('getUniqueByUri', async () => {
44
- const client = (await createInitializedClients(testBuilder))[0];
45
- const registry = createRegistry(client);
46
- await registry.open();
47
- for (let i = 0; i < 2; i++) {
48
- const space = await client.spaces.create();
49
- await registry.register(space, testManifest.functions);
50
- }
51
- const definitions = registry.getUniqueByUri();
52
- expect(definitions.length).to.eq(testManifest.functions?.length);
53
- });
54
-
55
- describe('register', () => {
56
- test('creates new functions', async () => {
57
- const client = (await createInitializedClients(testBuilder))[0];
58
- const registry = createRegistry(client);
59
- const space = await client.spaces.create();
60
- await registry.register(space, testManifest.functions);
61
- const { objects: definitions } = await space.db.query(Filter.schema(FunctionDef)).run();
62
- expect(definitions.length).to.eq(1);
63
- expect(definitions[0].uri).to.eq(testManifest.functions?.[0]?.uri);
64
- });
65
-
66
- test('de-duplicates by function URI', async () => {
67
- const client = (await createInitializedClients(testBuilder))[0];
68
- const registry = createRegistry(client);
69
- const space = await client.spaces.create();
70
- const existing = space.db.add(live(FunctionDef, testManifest.functions![0]));
71
- await registry.register(space, testManifest.functions);
72
- const { objects: definitions } = await space.db.query(Filter.schema(FunctionDef)).run();
73
- expect(definitions.length).to.eq(1);
74
- expect(definitions[0].uri).to.eq(existing.uri);
75
- });
76
- });
77
-
78
- describe('onFunctionsRegistered', () => {
79
- test('called with all registered when opened', async () => {
80
- const client = (await createInitializedClients(testBuilder))[0];
81
- const registry = createRegistry(client);
82
- const space = await client.spaces.create();
83
- const definitions = range(3, () => live(FunctionDef, testManifest.functions![0]));
84
- definitions.forEach((def) => space.db.add(def));
85
-
86
- const functionRegistered = new Trigger<FunctionDef[]>();
87
- registry.registered.on((fn) => {
88
- functionRegistered.wake(fn.added);
89
- });
90
- void registry.open(ctx);
91
- const functions = await functionRegistered.wait();
92
- const expected = definitions.map((def) => def.uri).sort();
93
- expect(functions.map((fn) => fn.uri).sort()).to.deep.eq(expected);
94
- });
95
-
96
- test('called when a new functions is added', async () => {
97
- const client = (await createInitializedClients(testBuilder))[0];
98
- const registry = createRegistry(client);
99
- const space = await client.spaces.create();
100
-
101
- const functionRegistered = new Trigger<FunctionDef>();
102
- registry.registered.on((fn) => {
103
- expect(fn.added.length).to.eq(1);
104
- functionRegistered.wake(fn.added[0]);
105
- });
106
- await registry.open(ctx);
107
- await registry.register(space, testManifest.functions);
108
- const registered = await functionRegistered.wait();
109
- expect(registered.uri).to.eq(testManifest.functions![0].uri);
110
- });
111
- });
112
-
113
- const createRegistry = (client: Client) => {
114
- const registry = new FunctionRegistry(client);
115
- ctx.onDispose(() => registry.close());
116
- return registry;
117
- };
118
- });
@@ -1,104 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Event } from '@dxos/async';
6
- import { type Client } from '@dxos/client';
7
- import { live, Filter, type Space } from '@dxos/client/echo';
8
- import { type Context, Resource } from '@dxos/context';
9
- import { PublicKey } from '@dxos/keys';
10
- import { log } from '@dxos/log';
11
- import { ComplexMap, diff } from '@dxos/util';
12
-
13
- import { FunctionDef, type FunctionManifest } from '../types';
14
-
15
- export type FunctionsRegisteredEvent = {
16
- space: Space;
17
- added: FunctionDef[];
18
- };
19
-
20
- export class FunctionRegistry extends Resource {
21
- private readonly _functionBySpaceKey = new ComplexMap<PublicKey, FunctionDef[]>(PublicKey.hash);
22
-
23
- public readonly registered = new Event<FunctionsRegisteredEvent>();
24
-
25
- constructor(private readonly _client: Client) {
26
- super();
27
- }
28
-
29
- public getFunctions(space: Space): FunctionDef[] {
30
- return this._functionBySpaceKey.get(space.key) ?? [];
31
- }
32
-
33
- public getUniqueByUri(): FunctionDef[] {
34
- const uniqueByUri = [...this._functionBySpaceKey.values()]
35
- .flatMap((defs) => defs)
36
- .reduce((acc, v) => {
37
- acc.set(v.uri, v);
38
- return acc;
39
- }, new Map<string, FunctionDef>());
40
- return [...uniqueByUri.values()];
41
- }
42
-
43
- /**
44
- * Loads function definitions from the manifest into the space.
45
- * We first load all the definitions from the space to deduplicate by functionId.
46
- */
47
- public async register(space: Space, functions: FunctionManifest['functions']): Promise<void> {
48
- log('register', { space: space.key, functions: functions?.length ?? 0 });
49
- if (!functions?.length) {
50
- return;
51
- }
52
- if (!space.db.graph.schemaRegistry.hasSchema(FunctionDef)) {
53
- space.db.graph.schemaRegistry.addSchema([FunctionDef]);
54
- }
55
-
56
- // Sync definitions.
57
- const { objects: existing } = await space.db.query(Filter.schema(FunctionDef)).run();
58
- const { added } = diff(existing, functions, (a, b) => a.uri === b.uri);
59
- // TODO(burdon): Update existing templates.
60
- added.forEach((def) => space.db.add(live(FunctionDef, def)));
61
-
62
- if (added.length > 0) {
63
- await space.db.flush({ indexes: true, updates: true });
64
- }
65
- }
66
-
67
- protected override async _open(): Promise<void> {
68
- log.info('opening...');
69
- const spacesSubscription = this._client.spaces.subscribe(async (spaces) => {
70
- for (const space of spaces) {
71
- if (this._functionBySpaceKey.has(space.key)) {
72
- continue;
73
- }
74
-
75
- const registered: FunctionDef[] = [];
76
- this._functionBySpaceKey.set(space.key, registered);
77
- await space.waitUntilReady();
78
- if (this._ctx.disposed) {
79
- break;
80
- }
81
-
82
- // Subscribe to updates.
83
- this._ctx.onDispose(
84
- space.db.query(Filter.schema(FunctionDef)).subscribe(({ objects }) => {
85
- const { added } = diff(registered, objects, (a, b) => a.uri === b.uri);
86
- // TODO(burdon): Update and remove.
87
- if (added.length > 0) {
88
- registered.push(...added);
89
- this.registered.emit({ space, added });
90
- }
91
- }),
92
- );
93
- }
94
- });
95
-
96
- // TODO(burdon): API: Normalize unsubscribe methods.
97
- this._ctx.onDispose(() => spacesSubscription.unsubscribe());
98
- }
99
-
100
- protected override async _close(_: Context): Promise<void> {
101
- log.info('closing...');
102
- this._functionBySpaceKey.clear();
103
- }
104
- }
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from './function-registry';