@omriashke/dynamico-core 0.1.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.
- package/LICENSE +184 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +16 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +31 -0
- package/dist/loader.js.map +1 -0
- package/dist/propsSchema.d.ts +7 -0
- package/dist/propsSchema.d.ts.map +1 -0
- package/dist/propsSchema.js +34 -0
- package/dist/propsSchema.js.map +1 -0
- package/dist/react/createRuntime.d.ts +22 -0
- package/dist/react/createRuntime.d.ts.map +1 -0
- package/dist/react/createRuntime.js +116 -0
- package/dist/react/createRuntime.js.map +1 -0
- package/dist/registry.d.ts +55 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +231 -0
- package/dist/registry.js.map +1 -0
- package/dist/sources/remote.d.ts +21 -0
- package/dist/sources/remote.d.ts.map +1 -0
- package/dist/sources/remote.js +102 -0
- package/dist/sources/remote.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -0
- package/src/index.ts +28 -0
- package/src/loader.ts +40 -0
- package/src/propsSchema.ts +43 -0
- package/src/react/createRuntime.tsx +189 -0
- package/src/registry.ts +240 -0
- package/src/sources/remote.ts +119 -0
- package/src/types.ts +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of developing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and incorporated
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or
|
|
82
|
+
contributory patent infringement, then any patent licenses granted
|
|
83
|
+
to You under this License for that Work shall terminate as of the
|
|
84
|
+
date such litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or in addition to the
|
|
115
|
+
NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
You may add Your own license statement for Your modifications and
|
|
119
|
+
may provide additional grant of rights to use, reproduce, modify,
|
|
120
|
+
prepare Derivative Works of, convert to Object form, display,
|
|
121
|
+
perform, sublicense, and distribute the Work and such Derivative
|
|
122
|
+
Works in Source or Object form.
|
|
123
|
+
|
|
124
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
125
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
126
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
127
|
+
this License, without any additional terms or conditions.
|
|
128
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
129
|
+
the terms of any separate license agreement you may have executed
|
|
130
|
+
with Licensor regarding such Contributions.
|
|
131
|
+
|
|
132
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
133
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
134
|
+
except as required for reasonable and customary use in describing the
|
|
135
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
136
|
+
|
|
137
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
138
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
139
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
140
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
141
|
+
implied, including, without limitation, any warranties or conditions
|
|
142
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
143
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
144
|
+
appropriateness of using or redistributing the Work and assume any
|
|
145
|
+
risks associated with Your exercise of permissions under this License.
|
|
146
|
+
|
|
147
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
148
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
149
|
+
unless required by applicable law (such as deliberate and grossly
|
|
150
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
151
|
+
liable to You for damages, including any direct, indirect, special,
|
|
152
|
+
incidental, or exemplary damages of any character arising as a
|
|
153
|
+
result of this License or out of the use or inability to use the
|
|
154
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
155
|
+
work stoppage, computer failure or malfunction, or all other
|
|
156
|
+
commercial damages or losses), even if such Contributor has been
|
|
157
|
+
advised of the possibility of such damages.
|
|
158
|
+
|
|
159
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
160
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
161
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
162
|
+
or other liability obligations and/or rights consistent with this
|
|
163
|
+
License. However, in accepting such obligations, You may offer such
|
|
164
|
+
obligations only on Your own behalf and on Your sole responsibility,
|
|
165
|
+
not on behalf of any other Contributor, and only if You agree to
|
|
166
|
+
indemnify, defend, and hold each Contributor harmless for any
|
|
167
|
+
liability incurred by, or claims asserted against, such Contributor
|
|
168
|
+
by reason of your accepting any such warranty or additional liability.
|
|
169
|
+
|
|
170
|
+
END OF TERMS AND CONDITIONS
|
|
171
|
+
|
|
172
|
+
Copyright 2024 Omri Askenazi
|
|
173
|
+
|
|
174
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
175
|
+
you may not use this file except in compliance with the License.
|
|
176
|
+
You may obtain a copy of the License at
|
|
177
|
+
|
|
178
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
179
|
+
|
|
180
|
+
Unless required by applicable law or agreed to in writing, software
|
|
181
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
182
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
183
|
+
See the License for the specific language governing permissions and
|
|
184
|
+
limitations under the License.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { Source, SourceUpdate, CompiledModule, CompiledModuleOk, CompiledModuleError, CompiledModuleRemoved, ComponentFactory, RegistryEntry, RegistryListener, Scope, PropsSchema, PropsSchemaField, DynamicError, Diagnostic, Version, } from "./types.js";
|
|
2
|
+
export { Registry } from "./registry.js";
|
|
3
|
+
export { loadModule } from "./loader.js";
|
|
4
|
+
export { createRemoteSource, type RemoteSourceOptions } from "./sources/remote.js";
|
|
5
|
+
export { validateProps, type PropsValidationResult } from "./propsSchema.js";
|
|
6
|
+
export { createRuntime, type RuntimeAPI, type DynamicoProviderProps, type DynamicComponentProps, } from "./react/createRuntime.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,MAAM,EACN,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EACL,aAAa,EACb,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,GAC3B,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Registry } from "./registry.js";
|
|
2
|
+
export { loadModule } from "./loader.js";
|
|
3
|
+
export { createRemoteSource } from "./sources/remote.js";
|
|
4
|
+
export { validateProps } from "./propsSchema.js";
|
|
5
|
+
export { createRuntime, } from "./react/createRuntime.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAA4B,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,aAAa,EAA8B,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EACL,aAAa,GAId,MAAM,0BAA0B,CAAC"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Scope } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Execute a CommonJS-style code string in a controlled scope.
|
|
4
|
+
*
|
|
5
|
+
* The compiler (server-side Babel) emits code that uses `require(name)`,
|
|
6
|
+
* `module.exports`, and `exports`. We give it a `require` that:
|
|
7
|
+
* - returns the host-registered binding for any bare specifier in `scope`
|
|
8
|
+
* - delegates relative paths ("./Other", "../foo") to `requireRelative`,
|
|
9
|
+
* which the registry implements by looking up other dynamic components
|
|
10
|
+
* - throws otherwise (no arbitrary npm imports at runtime)
|
|
11
|
+
*
|
|
12
|
+
* This is the only place we call `new Function`. It runs in the same realm
|
|
13
|
+
* as the host app — v1 trusts the registry; sandboxing is a v2 concern.
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadModule(code: string, scope: Scope, requireRelative: (specifier: string) => unknown): unknown;
|
|
16
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,GAC9C,OAAO,CAoBT"}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a CommonJS-style code string in a controlled scope.
|
|
3
|
+
*
|
|
4
|
+
* The compiler (server-side Babel) emits code that uses `require(name)`,
|
|
5
|
+
* `module.exports`, and `exports`. We give it a `require` that:
|
|
6
|
+
* - returns the host-registered binding for any bare specifier in `scope`
|
|
7
|
+
* - delegates relative paths ("./Other", "../foo") to `requireRelative`,
|
|
8
|
+
* which the registry implements by looking up other dynamic components
|
|
9
|
+
* - throws otherwise (no arbitrary npm imports at runtime)
|
|
10
|
+
*
|
|
11
|
+
* This is the only place we call `new Function`. It runs in the same realm
|
|
12
|
+
* as the host app — v1 trusts the registry; sandboxing is a v2 concern.
|
|
13
|
+
*/
|
|
14
|
+
export function loadModule(code, scope, requireRelative) {
|
|
15
|
+
const moduleObj = { exports: {} };
|
|
16
|
+
const requireFn = (name) => {
|
|
17
|
+
if (name.startsWith("./") || name.startsWith("../") || name.startsWith("/")) {
|
|
18
|
+
return requireRelative(name);
|
|
19
|
+
}
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(scope, name)) {
|
|
21
|
+
return scope[name];
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`dynamico: '${name}' is not in host scope. Add it via <DynamicoProvider scope={{...}}>.`);
|
|
24
|
+
};
|
|
25
|
+
// The compiled body is just the function body; arguments are well-known.
|
|
26
|
+
// eslint-disable-next-line no-new-func
|
|
27
|
+
const fn = new Function("module", "exports", "require", code);
|
|
28
|
+
fn(moduleObj, moduleObj.exports, requireFn);
|
|
29
|
+
return moduleObj.exports;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CACxB,IAAY,EACZ,KAAY,EACZ,eAA+C;IAE/C,MAAM,SAAS,GAAG,EAAE,OAAO,EAAE,EAA6B,EAAE,CAAC;IAC7D,MAAM,SAAS,GAAG,CAAC,IAAY,EAAW,EAAE;QAC1C,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5E,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;YACtD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QACD,MAAM,IAAI,KAAK,CACb,cAAc,IAAI,sEAAsE,CACzF,CAAC;IACJ,CAAC,CAAC;IAEF,yEAAyE;IACzE,uCAAuC;IACvC,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC9D,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAE5C,OAAO,SAAS,CAAC,OAAO,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PropsSchema } from "./types.js";
|
|
2
|
+
export interface PropsValidationResult {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
errors: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function validateProps(schema: PropsSchema | undefined, props: Record<string, unknown>): PropsValidationResult;
|
|
7
|
+
//# sourceMappingURL=propsSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propsSchema.d.ts","sourceRoot":"","sources":["../src/propsSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAWD,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,qBAAqB,CAiBvB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const TYPE_CHECKS = {
|
|
2
|
+
string: (v) => typeof v === "string",
|
|
3
|
+
number: (v) => typeof v === "number" && !Number.isNaN(v),
|
|
4
|
+
boolean: (v) => typeof v === "boolean",
|
|
5
|
+
object: (v) => typeof v === "object" && v !== null && !Array.isArray(v),
|
|
6
|
+
array: (v) => Array.isArray(v),
|
|
7
|
+
any: () => true,
|
|
8
|
+
};
|
|
9
|
+
export function validateProps(schema, props) {
|
|
10
|
+
if (!schema)
|
|
11
|
+
return { ok: true, errors: [] };
|
|
12
|
+
const errors = [];
|
|
13
|
+
for (const [key, field] of Object.entries(schema)) {
|
|
14
|
+
const present = Object.prototype.hasOwnProperty.call(props, key);
|
|
15
|
+
if (!present) {
|
|
16
|
+
if (field.required)
|
|
17
|
+
errors.push(`missing required prop '${key}' (${field.type})`);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const checker = TYPE_CHECKS[field.type] ?? TYPE_CHECKS.any;
|
|
21
|
+
if (!checker(props[key])) {
|
|
22
|
+
errors.push(`prop '${key}' expected ${field.type}, got ${describe(props[key])}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { ok: errors.length === 0, errors };
|
|
26
|
+
}
|
|
27
|
+
function describe(v) {
|
|
28
|
+
if (v === null)
|
|
29
|
+
return "null";
|
|
30
|
+
if (Array.isArray(v))
|
|
31
|
+
return "array";
|
|
32
|
+
return typeof v;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=propsSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propsSchema.js","sourceRoot":"","sources":["../src/propsSchema.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,GAA4C;IAC3D,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ;IACpC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACxD,OAAO,EAA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D,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;AAC7C,CAAC;AAED,SAAS,QAAQ,CAAC,CAAU;IAC1B,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,OAAO,CAAC;IACrC,OAAO,OAAO,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { DynamicError, RegistryEntry, Scope, Source } from "../types.js";
|
|
3
|
+
export interface RuntimeAPI {
|
|
4
|
+
DynamicoProvider: React.ComponentType<DynamicoProviderProps>;
|
|
5
|
+
DynamicComponent: React.ComponentType<DynamicComponentProps>;
|
|
6
|
+
useDynamico: (name: string) => RegistryEntry | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface DynamicoProviderProps {
|
|
9
|
+
source: Source;
|
|
10
|
+
scope?: Scope;
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export interface DynamicComponentProps {
|
|
14
|
+
name: string;
|
|
15
|
+
props?: Record<string, unknown>;
|
|
16
|
+
fallback?: React.ReactNode;
|
|
17
|
+
errorFallback?: React.ComponentType<{
|
|
18
|
+
error: DynamicError;
|
|
19
|
+
}> | React.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export declare function createRuntime(defaultScope: Scope): RuntimeAPI;
|
|
22
|
+
//# sourceMappingURL=createRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRuntime.d.ts","sourceRoot":"","sources":["../../src/react/createRuntime.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAEV,YAAY,EAEZ,aAAa,EACb,KAAK,EACL,MAAM,EACP,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,UAAU;IACzB,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;IAC7D,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;IAC7D,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,aAAa,GAAG,SAAS,CAAC;CAC1D;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;CAChF;AAMD,wBAAgB,aAAa,CAAC,YAAY,EAAE,KAAK,GAAG,UAAU,CA8F7D"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Registry } from "../registry.js";
|
|
4
|
+
import { validateProps } from "../propsSchema.js";
|
|
5
|
+
export function createRuntime(defaultScope) {
|
|
6
|
+
const Ctx = React.createContext(null);
|
|
7
|
+
function DynamicoProvider({ source, scope, children }) {
|
|
8
|
+
const registry = React.useMemo(() => {
|
|
9
|
+
const merged = { ...defaultScope, ...(scope ?? {}) };
|
|
10
|
+
return new Registry(source, merged);
|
|
11
|
+
}, [source, scope]);
|
|
12
|
+
const value = React.useMemo(() => ({ registry }), [registry]);
|
|
13
|
+
return _jsx(Ctx.Provider, { value: value, children: children });
|
|
14
|
+
}
|
|
15
|
+
function useRegistry() {
|
|
16
|
+
const ctx = React.useContext(Ctx);
|
|
17
|
+
if (!ctx) {
|
|
18
|
+
throw new Error("dynamico: useDynamico/DynamicComponent must be inside <DynamicoProvider>");
|
|
19
|
+
}
|
|
20
|
+
return ctx.registry;
|
|
21
|
+
}
|
|
22
|
+
function useDynamico(name) {
|
|
23
|
+
const registry = useRegistry();
|
|
24
|
+
const subscribe = React.useCallback((cb) => registry.subscribe(name, cb), [registry, name]);
|
|
25
|
+
const getSnapshot = React.useCallback(() => registry.peek(name), [registry, name]);
|
|
26
|
+
const entry = React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
if (!registry.peek(name))
|
|
29
|
+
void registry.ensure(name);
|
|
30
|
+
}, [registry, name]);
|
|
31
|
+
return entry;
|
|
32
|
+
}
|
|
33
|
+
function DynamicComponent({ name, props, fallback = null, errorFallback, }) {
|
|
34
|
+
const entry = useDynamico(name);
|
|
35
|
+
if (!entry)
|
|
36
|
+
return _jsx(_Fragment, { children: fallback });
|
|
37
|
+
if (entry.error) {
|
|
38
|
+
return _jsx(_Fragment, { children: renderError(errorFallback, entry.error) });
|
|
39
|
+
}
|
|
40
|
+
if (!entry.factory)
|
|
41
|
+
return _jsx(_Fragment, { children: fallback });
|
|
42
|
+
const Comp = pickDefault(entry.factory);
|
|
43
|
+
if (typeof Comp !== "function") {
|
|
44
|
+
const err = {
|
|
45
|
+
kind: "load",
|
|
46
|
+
name,
|
|
47
|
+
version: entry.version,
|
|
48
|
+
message: `component '${name}' has no default export of a function/class`,
|
|
49
|
+
};
|
|
50
|
+
return _jsx(_Fragment, { children: renderError(errorFallback, err) });
|
|
51
|
+
}
|
|
52
|
+
const schema = entry.factory.propsSchema;
|
|
53
|
+
const validation = validateProps(schema, props ?? {});
|
|
54
|
+
if (!validation.ok) {
|
|
55
|
+
const err = {
|
|
56
|
+
kind: "render",
|
|
57
|
+
name,
|
|
58
|
+
version: entry.version,
|
|
59
|
+
message: `props validation failed: ${validation.errors.join("; ")}`,
|
|
60
|
+
};
|
|
61
|
+
return _jsx(_Fragment, { children: renderError(errorFallback, err) });
|
|
62
|
+
}
|
|
63
|
+
return (_jsx(ErrorBoundary, { onError: (message, stack) => ({
|
|
64
|
+
kind: "render",
|
|
65
|
+
name,
|
|
66
|
+
version: entry.version,
|
|
67
|
+
message,
|
|
68
|
+
stack,
|
|
69
|
+
}), renderFallback: (err) => renderError(errorFallback, err), children: React.createElement(Comp, props ?? {}) }, `${name}@${entry.version}`));
|
|
70
|
+
}
|
|
71
|
+
return { DynamicoProvider, DynamicComponent, useDynamico };
|
|
72
|
+
}
|
|
73
|
+
function pickDefault(factory) {
|
|
74
|
+
if (factory && typeof factory === "object") {
|
|
75
|
+
if ("default" in factory && factory.default)
|
|
76
|
+
return factory.default;
|
|
77
|
+
// CommonJS interop: the value itself may be the component
|
|
78
|
+
if (typeof factory === "function")
|
|
79
|
+
return factory;
|
|
80
|
+
}
|
|
81
|
+
if (typeof factory === "function")
|
|
82
|
+
return factory;
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
function renderError(errorFallback, error) {
|
|
86
|
+
if (!errorFallback)
|
|
87
|
+
return defaultErrorView(error);
|
|
88
|
+
if (typeof errorFallback === "function") {
|
|
89
|
+
const Fallback = errorFallback;
|
|
90
|
+
return _jsx(Fallback, { error: error });
|
|
91
|
+
}
|
|
92
|
+
return errorFallback;
|
|
93
|
+
}
|
|
94
|
+
function defaultErrorView(error) {
|
|
95
|
+
// Renderer-agnostic: plain text node so it works on both DOM and RN.
|
|
96
|
+
return React.createElement(React.Fragment, null, `[dynamico ${error.kind} error] ${error.name}: ${error.message}`);
|
|
97
|
+
}
|
|
98
|
+
class ErrorBoundary extends React.Component {
|
|
99
|
+
constructor() {
|
|
100
|
+
super(...arguments);
|
|
101
|
+
this.state = { err: null };
|
|
102
|
+
}
|
|
103
|
+
static getDerivedStateFromError() {
|
|
104
|
+
return null; // we set state in componentDidCatch where we have the message
|
|
105
|
+
}
|
|
106
|
+
componentDidCatch(error) {
|
|
107
|
+
const e = error instanceof Error ? error : new Error(String(error));
|
|
108
|
+
this.setState({ err: this.props.onError(e.message, e.stack) });
|
|
109
|
+
}
|
|
110
|
+
render() {
|
|
111
|
+
if (this.state.err)
|
|
112
|
+
return this.props.renderFallback(this.state.err);
|
|
113
|
+
return this.props.children;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=createRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRuntime.js","sourceRoot":"","sources":["../../src/react/createRuntime.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAS1C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAyBlD,MAAM,UAAU,aAAa,CAAC,YAAmB;IAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,aAAa,CAA6B,IAAI,CAAC,CAAC;IAElE,SAAS,gBAAgB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAyB;QAC1E,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;YAClC,MAAM,MAAM,GAAU,EAAE,GAAG,YAAY,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;YAC5D,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAEpB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAsB,GAAG,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QACnF,OAAO,KAAC,GAAG,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,Y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D;IAAnF;;QACE,UAAK,GAAuB,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IAe5C,CAAC;IAbC,MAAM,CAAC,wBAAwB;QAC7B,OAAO,IAAI,CAAC,CAAC,8DAA8D;IAC7E,CAAC;IAED,iBAAiB,CAAC,KAAc;QAC9B,MAAM,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { RegistryEntry, RegistryListener, Scope, Source } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* In-memory, versioned registry of dynamic components.
|
|
4
|
+
*
|
|
5
|
+
* The registry is the single source of truth that runtime packages
|
|
6
|
+
* (@omriashke/dynamico-web, @omriashke/dynamico-native) subscribe to. It receives compiled
|
|
7
|
+
* modules from a Source, evaluates them via the loader using a host-provided
|
|
8
|
+
* Scope, and notifies subscribers when a component's version changes.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Registry {
|
|
11
|
+
private readonly source;
|
|
12
|
+
private scope;
|
|
13
|
+
private entries;
|
|
14
|
+
private listeners;
|
|
15
|
+
private anyListeners;
|
|
16
|
+
private inflight;
|
|
17
|
+
constructor(source: Source, scope: Scope);
|
|
18
|
+
/** Replace or extend the current scope (rare; typically set once). */
|
|
19
|
+
setScope(scope: Scope): void;
|
|
20
|
+
/** Get the current entry for a name, if any. */
|
|
21
|
+
peek(name: string): RegistryEntry | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Ensure a component is loaded. Triggers an initial fetch if we don't yet
|
|
24
|
+
* have an entry for this name. Returns the latest known entry.
|
|
25
|
+
*/
|
|
26
|
+
ensure(name: string): Promise<RegistryEntry>;
|
|
27
|
+
/** Subscribe to changes for a specific component. */
|
|
28
|
+
subscribe(name: string, listener: RegistryListener): () => void;
|
|
29
|
+
/** Subscribe to all changes (used internally / for debugging). */
|
|
30
|
+
subscribeAll(listener: RegistryListener): () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve a relative-path require from inside a dynamic component.
|
|
33
|
+
* Cross-component imports look up other components by name in the registry.
|
|
34
|
+
* v1: we map "./Other" -> "Other" (basename, no extension).
|
|
35
|
+
*
|
|
36
|
+
* The returned value is a *lazy proxy module*: it has the same shape as
|
|
37
|
+
* a real CommonJS module (`{ default, ...rest }`), but every member is a
|
|
38
|
+
* React function component that re-resolves the target on each render.
|
|
39
|
+
* This means:
|
|
40
|
+
* - Card can `require("./Hello")` at eval time even before Hello has
|
|
41
|
+
* loaded — the proxy is returned immediately.
|
|
42
|
+
* - When Hello actually arrives (or hot-swaps to a new version), Card's
|
|
43
|
+
* next render automatically picks it up; no manual preload needed.
|
|
44
|
+
*/
|
|
45
|
+
requireByPath(specifier: string): unknown;
|
|
46
|
+
private lazyProxies;
|
|
47
|
+
private makeLazyProxy;
|
|
48
|
+
/**
|
|
49
|
+
* Take a CompiledModule from the source, evaluate it (or record a compile
|
|
50
|
+
* error), update the entry, and notify listeners.
|
|
51
|
+
*/
|
|
52
|
+
private ingest;
|
|
53
|
+
private notify;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,aAAa,EACb,gBAAgB,EAChB,KAAK,EACL,MAAM,EAEP,MAAM,YAAY,CAAC;AAGpB;;;;;;;GAOG;AACH,qBAAa,QAAQ;IAOjB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,KAAK;IAPf,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,SAAS,CAA4C;IAC7D,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,QAAQ,CAA6C;gBAG1C,MAAM,EAAE,MAAM,EACvB,KAAK,EAAE,KAAK;IAOtB,sEAAsE;IACtE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAI5B,gDAAgD;IAChD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAI7C;;;OAGG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAelD,qDAAqD;IACrD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,MAAM,IAAI;IAa/D,kEAAkE;IAClE,YAAY,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,IAAI;IAOpD;;;;;;;;;;;;;OAaG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAezC,OAAO,CAAC,WAAW,CAA8C;IAEjE,OAAO,CAAC,aAAa;IA6CrB;;;OAGG;IACH,OAAO,CAAC,MAAM;IAiDd,OAAO,CAAC,MAAM;CAoBf"}
|