@ibyar/expressions 0.5.62 → 0.6.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/scope/stack.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { DeclarationExpression } from '../api/expression.js';
2
- import { ModuleScope, ReactiveScope, Scope, ScopeContext, WebModuleScope } from './scope.js';
2
+ import { ModuleScope, ReactiveScope, Scope, Context, WebModuleScope } from './scope.js';
3
3
  export interface AwaitPromiseInfo {
4
4
  promise: Promise<any>;
5
5
  node: DeclarationExpression;
@@ -53,29 +53,29 @@ export interface Stack {
53
53
  * if not found will return the stack local scop as a default value
54
54
  * @param propertyKey the property key
55
55
  */
56
- findScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;
56
+ findScope<T extends Context>(propertyKey: PropertyKey): Scope<T>;
57
57
  resolveAwait(value: AwaitPromiseInfo): void;
58
58
  /**
59
59
  * get a reference to the last scope in this stack
60
60
  */
61
- lastScope<T extends ScopeContext>(): Scope<T>;
61
+ lastScope<T extends Context>(): Scope<T>;
62
62
  /**
63
63
  * clear every thing after this scope, and even this scope
64
64
  * @param scope
65
65
  */
66
- clearTo<T extends ScopeContext>(scope: Scope<T>): boolean;
66
+ clearTo<T extends Context>(scope: Scope<T>): boolean;
67
67
  /**
68
68
  * clear every thing after this scope, but not this scope
69
69
  * @param scope
70
70
  */
71
- clearTill<T extends ScopeContext>(scope: Scope<T>): boolean;
72
- popScope<T extends ScopeContext>(): Scope<T>;
73
- removeScope<T extends ScopeContext>(scope: Scope<T>): void;
74
- pushScope<T extends ScopeContext>(scope: Scope<T>): void;
75
- pushBlockScope<T extends ScopeContext>(): Scope<T>;
76
- pushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;
77
- pushReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
78
- pushReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
71
+ clearTill<T extends Context>(scope: Scope<T>): boolean;
72
+ popScope<T extends Context>(): Scope<T>;
73
+ removeScope<T extends Context>(scope: Scope<T>): void;
74
+ pushScope<T extends Context>(scope: Scope<T>): void;
75
+ pushBlockScope<T extends Context>(): Scope<T>;
76
+ pushBlockScopeFor<T extends Context>(context: T): Scope<T>;
77
+ pushReactiveScope<T extends Context>(): ReactiveScope<T>;
78
+ pushReactiveScopeFor<T extends Context>(context: T): ReactiveScope<T>;
79
79
  /**
80
80
  * create new stack instance with the same reference to the current scope array
81
81
  */
@@ -107,9 +107,9 @@ export interface Stack {
107
107
  onDestroy(action: () => void): void;
108
108
  }
109
109
  export declare class Stack implements Stack {
110
- static for(...contexts: Scope<ScopeContext>[]): Stack;
111
- static forScopes(...scopes: Scope<ScopeContext>[]): Stack;
112
- static moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<ScopeContext>[]): Stack;
110
+ static for(...contexts: Scope<Context>[]): Stack;
111
+ static forScopes(...scopes: Scope<Context>[]): Stack;
112
+ static moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<Context>[]): Stack;
113
113
  awaitPromise: AwaitPromiseInfo[];
114
114
  forAwaitAsyncIterable?: AsyncIterableInfo | undefined;
115
115
  protected readonly stack: Array<Scope<any>>;
@@ -118,12 +118,14 @@ export declare class Stack implements Stack {
118
118
  protected readonly resolver?: ModuleScopeResolver;
119
119
  protected readonly onDestroyActions: (() => void)[];
120
120
  constructor();
121
- constructor(globalScope: Scope<ScopeContext>);
122
- constructor(globalScope: Scope<ScopeContext>, resolver: ModuleScopeResolver, moduleSource: string);
123
- constructor(stack: Array<Scope<ScopeContext>>);
124
- constructor(stack: Array<Scope<ScopeContext>>, resolver: ModuleScopeResolver, moduleSource: string);
121
+ constructor(globalScope: Scope<Context>);
122
+ constructor(globalScope: Scope<Context>, resolver: ModuleScopeResolver, moduleSource: string);
123
+ constructor(stack: Array<Scope<Context>>);
124
+ constructor(stack: Array<Scope<Context>>, resolver: ModuleScopeResolver, moduleSource: string);
125
125
  private initModuleContext;
126
+ detectChanges(): void;
126
127
  private getReactiveScopeControls;
128
+ private getReactiveScope;
127
129
  }
128
130
  export interface ModuleScopeResolver {
129
131
  resolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;
package/scope/stack.js CHANGED
@@ -2,6 +2,7 @@ import { finalizerRegister } from './finalizer.js';
2
2
  import { ModuleScope, ReactiveScope, ReactiveScopeControl, Scope, WebModuleScope } from './scope.js';
3
3
  export class Stack {
4
4
  constructor(globals, resolver, moduleSource) {
5
+ this.awaitPromise = [];
5
6
  this.onDestroyActions = [];
6
7
  if (Array.isArray(globals)) {
7
8
  this.stack = globals;
@@ -138,9 +139,15 @@ export class Stack {
138
139
  reattach() {
139
140
  this.getReactiveScopeControls().forEach(scope => scope.reattach());
140
141
  }
142
+ detectChanges() {
143
+ this.getReactiveScope().forEach(scope => scope.detectChanges());
144
+ }
141
145
  getReactiveScopeControls() {
142
146
  return this.stack.filter(scope => scope instanceof ReactiveScopeControl);
143
147
  }
148
+ getReactiveScope() {
149
+ return this.stack.filter(scope => scope instanceof ReactiveScope);
150
+ }
144
151
  importModule(source, importCallOptions) {
145
152
  if (!this.resolver || !this.moduleScope) {
146
153
  // should o the parse and import the module
@@ -1 +1 @@
1
- {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/expressions/scope/stack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACuB,WAAW,EAAE,aAAa,EACvD,oBAAoB,EAAE,KAAK,EAAgB,cAAc,EACzD,MAAM,YAAY,CAAC;AAyIpB,MAAM,OAAO,KAAK;IAiCjB,YAAY,OAA0D,EAAE,QAA8B,EAAE,YAAqB;QAT1G,qBAAgB,GAAmB,EAAE,CAAC;QAUxD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;SACrB;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AA;QACrC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtC,eAAe;QACf,oCAAoC;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YAC5B,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IACjB,CAAC;CAUD","sourcesContent":["import type { DeclarationExpression } from '../api/expression.js';\nimport { finalizerRegister } from './finalizer.js';\nimport {\n\tModuleContext, ModuleImport, ModuleScope, ReactiveScope,\n\tReactiveScopeControl, Scope, ScopeContext, WebModuleScope\n} from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: DeclarationExpression;\n\n\tdeclareVariable: boolean;\n}\n\nexport interface AsyncIterableInfo {\n\titerable: AsyncIterable<any>;\n\tforAwaitBody: (iterator: any) => any;\n}\n\nexport interface Stack {\n\t/**\n\t * a list of promises to resolve in an 'async' scope as 'async function'\n\t */\n\tawaitPromise: Array<AwaitPromiseInfo>;\n\n\t/**\n\t * resolve await promise in 'await for in' scope\n\t */\n\tforAwaitAsyncIterable?: AsyncIterableInfo;\n\n\t/**\n\t * is this stack has a propertyKey\n\t * @param propertyKey \n\t */\n\thas(propertyKey: PropertyKey): boolean;\n\n\t/**\n\t * get the first value for provided property key,\n\t * \n\t * will search current stack in all scope till find the first key, else undefined\n\t * @param propertyKey \n\t */\n\tget(propertyKey: PropertyKey): any;\n\n\t/**\n\t * set the value of `propertyKey` in its context provider with `value`.\n\t * else define it in the first scope 'local scope'\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean;\n\n\t/**\n\t * declare variable at last scope in the stack,\n\t * \n\t * @param propertyKey the name of property mey be string | number | symbol, \n\t * @param propertyValue if not exist will be initialize with 'undefined' value\n\t */\n\tdeclareVariable(propertyKey: PropertyKey, propertyValue?: any): any;\n\n\n\t/**\n\t * get context object of this provider,\n\t * search for the first context object that has `propertyKey`.\n\t * \n\t * search for the first context that have property key,\n\t * if not found will return the stack local scop as a default value\n\t * @param propertyKey the property key\n\t */\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;\n\n\tresolveAwait(value: AwaitPromiseInfo): void;\n\n\t/**\n\t * get a reference to the last scope in this stack\n\t */\n\tlastScope<T extends ScopeContext>(): Scope<T>;\n\n\t/**\n\t * clear every thing after this scope, and even this scope\n\t * @param scope \n\t */\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\t/**\n\t * clear every thing after this scope, but not this scope\n\t * @param scope \n\t */\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends ScopeContext>(): Scope<T>;\n\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends ScopeContext>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;\n\n\tpushReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;\n\n\tpushReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;\n\n\t/**\n\t * create new stack instance with the same reference to the current scope array\n\t */\n\tcopyStack(): Stack;\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tdetach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\treattach(): void;\n\n\t/**\n\t * import module scope from another stack, by the help of ModuleScopeResolver.\n\t * \n\t * used with import statement\n\t */\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope;\n\n\t/**\n\t * get the current module for this stack.\n\t * \n\t * used with export statement\n\t */\n\tgetModule(): ModuleScope | undefined;\n\n\t/**\n\t * register action to do on destroy this stack\n\t */\n\tonDestroy(action: () => void): void;\n}\n\nexport class Stack implements Stack {\n\tstatic for(...contexts: Scope<ScopeContext>[]): Stack {\n\t\tif (contexts.length === 0) {\n\t\t\treturn new Stack();\n\t\t}\n\t\treturn new Stack(contexts.map(context => new Scope<ScopeContext>(context)));\n\t}\n\tstatic forScopes(...scopes: Scope<ScopeContext>[]): Stack {\n\t\tif (scopes.length === 0) {\n\t\t\tscopes.push(Scope.blockScope());\n\t\t}\n\t\treturn new Stack(scopes);\n\t}\n\tstatic moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<ScopeContext>[]) {\n\t\treturn new Stack(globalScopes, resolver, moduleSource);\n\t}\n\tawaitPromise: AwaitPromiseInfo[];\n\tforAwaitAsyncIterable?: AsyncIterableInfo | undefined;\n\n\tprotected readonly stack: Array<Scope<any>>;\n\tprotected readonly moduleScope?: ModuleScope;\n\tprotected readonly moduleSource?: string;\n\tprotected readonly resolver?: ModuleScopeResolver;\n\n\tprotected readonly onDestroyActions: (() => void)[] = [];\n\n\tconstructor();\n\tconstructor(globalScope: Scope<ScopeContext>);\n\tconstructor(globalScope: Scope<ScopeContext>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(stack: Array<Scope<ScopeContext>>);\n\tconstructor(stack: Array<Scope<ScopeContext>>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(globals?: Array<Scope<ScopeContext>> | Scope<ScopeContext>, resolver?: ModuleScopeResolver, moduleSource?: string) {\n\t\tif (Array.isArray(globals)) {\n\t\t\tthis.stack = globals;\n\t\t} else if (typeof globals == 'object') {\n\t\t\tthis.stack = [globals];\n\t\t} else {\n\t\t\tthis.stack = [];\n\t\t}\n\t\tif (resolver && moduleSource) {\n\t\t\tthis.resolver = resolver;\n\t\t\tthis.moduleSource = moduleSource;\n\t\t\t// init module scope for import and export\n\t\t\tthis.moduleScope = new ModuleScope(this.initModuleContext());\n\t\t\tthis.pushScope(this.moduleScope);\n\t\t\t// for the rest of module body\n\t\t\tthis.pushReactiveScope();\n\t\t} else {\n\t\t\t// not a module scope\n\t\t\tthis.pushBlockScope();\n\t\t}\n\t\tfinalizerRegister(this, this.onDestroyActions, this);\n\t}\n\tprivate initModuleContext(): ModuleContext {\n\t\tconst importFunc = (path: string) => {\n\t\t\treturn this.importModule(path);\n\t\t};\n\t\timportFunc.meta = {\n\t\t\turl: createRootURL(this.moduleSource!),\n\t\t\tresolve: (specified: string, parent?: string | URL): Promise<string> => {\n\t\t\t\treturn Promise.resolve(this.resolver!.resolveURL(specified, parent ?? importFunc.meta.url));\n\t\t\t}\n\t\t};\n\t\tconst im: ModuleImport & ((path: string) => Promise<any>) = importFunc as any;\n\t\treturn { import: im };\n\t}\n\thas(propertyKey: PropertyKey): boolean {\n\t\treturn this.stack.find(context => context.has(propertyKey)) ? true : false;\n\t}\n\tget(propertyKey: PropertyKey) {\n\t\treturn this.findScope<ScopeContext>(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope<ScopeContext>(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(propertyKey: PropertyKey, propertyValue?: any) {\n\t\treturn this.lastScope<ScopeContext>().set(propertyKey, propertyValue);\n\t}\n\tfindScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T> {\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.has(propertyKey)) {\n\t\t\t\treturn scope;\n\t\t\t}\n\t\t}\n\t\treturn this.lastScope();\n\t}\n\tresolveAwait(value: AwaitPromiseInfo): void {\n\t\tthis.awaitPromise.push(value);\n\t}\n\tpopScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tthis.stack.splice(index, 1);\n\t}\n\tpushScope<T extends ScopeContext>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends ScopeContext>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T> {\n\t\tconst scope = Scope.for<T>(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScope<T extends ScopeContext>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.for(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tlastScope<T extends ScopeContext>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index);\n\t\treturn true;\n\t}\n\tclearTill<T extends ScopeContext>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index + 1);\n\t\treturn true;\n\t}\n\tcopyStack(): Stack {\n\t\treturn new Stack(this.stack.slice(), this.resolver!, this.moduleSource!);\n\t}\n\tdetach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.detach());\n\t}\n\treattach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.reattach());\n\t}\n\tprivate getReactiveScopeControls(): ReactiveScopeControl<any>[] {\n\t\treturn this.stack.filter(scope => scope instanceof ReactiveScopeControl) as ReactiveScopeControl<any>[];\n\t}\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (!this.resolver || !this.moduleScope) {\n\t\t\t// should o the parse and import the module\n\t\t\tthrow new Error('Module Resolver is undefined');\n\t\t}\n\t\treturn this.resolver.resolve(source, this.moduleScope, importCallOptions);\n\t}\n\tgetModule(): ModuleScope | undefined {\n\t\treturn this.moduleScope;\n\t}\n\n\tonDestroy(action: () => void): void {\n\t\tthis.onDestroyActions.push(action);\n\t}\n}\n\n\nexport interface ModuleScopeResolver {\n\tresolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;\n\tresolveURL(specified: string, parent: string | URL): string;\n}\n\nconst ROOT_URL = 'https://root';\nexport function createRootURL(source: string): URL {\n\treturn new URL(source, ROOT_URL);\n}\n\n\nexport interface ResolverConfig {\n\t/**\n\t * \n\t */\n\tallowImportExternal?: boolean;\n\n};\nexport class ModuleScopeResolver implements ModuleScopeResolver {\n\tprotected modules: [string, ModuleScope][] = [];\n\tconstructor(protected config?: ResolverConfig) { }\n\tregister(source: string, moduleScope: ModuleScope) {\n\t\tconst stackInfo = this.modules.find(tuple => tuple[0] == source && tuple[1] == moduleScope);\n\t\tif (stackInfo) {\n\t\t\tstackInfo[1] = moduleScope;\n\t\t} else {\n\t\t\tthis.modules.push([source, moduleScope]);\n\t\t}\n\t}\n\tresolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (this.isValidHTTPUrl(source)) {\n\t\t\treturn this.resolveExternalModule(source, importCallOptions);\n\t\t}\n\t\tif (source.startsWith('/')) {\n\t\t\treturn this.findScopeBySource(source, importCallOptions);\n\t\t}\n\t\tconst currentSource = this.findSourceByScope(moduleScope);\n\t\tconst absoluteUrl = this.resolveURL(source, currentSource);\n\t\treturn this.findScopeBySource(absoluteUrl, importCallOptions);\n\t}\n\tresolveURL(specified: string, parent: string | URL): string {\n\t\tconst currentUrl = parent instanceof URL ? parent.href : createRootURL(parent).href;\n\t\tconst importedUrl = new URL(specified, currentUrl).href;\n\t\tconst absoluteUrl = importedUrl.replace(ROOT_URL, '');\n\t\treturn absoluteUrl;\n\t}\n\tprotected findScopeBySource(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (importCallOptions?.assert?.type) {\n\t\t\tconst type = importCallOptions.assert.type;\n\t\t\tif (!source.endsWith(`.${type}`)) {\n\t\t\t\tthrow new Error(`Can't find module scope`);\n\t\t\t}\n\t\t}\n\t\tconst importedScope = this.modules.find(tuple => tuple[0] == source)?.[1];\n\t\tif (!importedScope) {\n\t\t\tthrow new Error(`Can't find module scope`);\n\t\t}\n\t\treturn importedScope;\n\t}\n\tprotected findSourceByScope(moduleScope: ModuleScope): string {\n\t\tconst importedSource = this.modules.find(tuple => tuple[1] == moduleScope)?.[0];\n\t\tif (!importedSource) {\n\t\t\tthrow new Error(`Can't resolve scope source`);\n\t\t}\n\t\treturn importedSource;\n\t}\n\tprotected resolveExternalModule(source: string, importCallOptions?: ImportCallOptions): WebModuleScope {\n\t\tif (!this.config?.allowImportExternal) {\n\t\t\tthrow new Error(`Error: Import External Module is not allowed.`);\n\t\t}\n\t\tconst webScope = new WebModuleScope()\n\t\tthis.modules.push([source, webScope]);\n\t\t// active later\n\t\t// import(source, importCallOptions)\n\t\timport(source).then(module => {\n\t\t\twebScope.updateContext(module);\n\t\t});\n\t\treturn webScope;\n\t}\n\tprotected readonly isValidHTTPUrl = (string: string) => {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(string);\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn url.protocol === 'http:' || url.protocol === 'https:';\n\t}\n}\n"]}
1
+ {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/expressions/scope/stack.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACuB,WAAW,EAAE,aAAa,EACvD,oBAAoB,EAAE,KAAK,EAAW,cAAc,EACpD,MAAM,YAAY,CAAC;AAyIpB,MAAM,OAAO,KAAK;IAiCjB,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wB;QACnD,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAChF,IAAI,CAAC,cAAc,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC9C;QACD,OAAO,cAAc,CAAC;IACvB,CAAC;IACS,qBAAqB,CAAC,MAAc,EAAE,iBAAqC;QACpF,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,mBAAmB,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;SACjE;QACD,MAAM,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAA;QACrC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtC,eAAe;QACf,oCAAoC;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YAC5B,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IACjB,CAAC;CAUD","sourcesContent":["import type { DeclarationExpression } from '../api/expression.js';\nimport { finalizerRegister } from './finalizer.js';\nimport {\n\tModuleContext, ModuleImport, ModuleScope, ReactiveScope,\n\tReactiveScopeControl, Scope, Context, WebModuleScope\n} from './scope.js';\n\n\nexport interface AwaitPromiseInfo {\n\tpromise: Promise<any>;\n\tnode: DeclarationExpression;\n\n\tdeclareVariable: boolean;\n}\n\nexport interface AsyncIterableInfo {\n\titerable: AsyncIterable<any>;\n\tforAwaitBody: (iterator: any) => any;\n}\n\nexport interface Stack {\n\t/**\n\t * a list of promises to resolve in an 'async' scope as 'async function'\n\t */\n\tawaitPromise: Array<AwaitPromiseInfo>;\n\n\t/**\n\t * resolve await promise in 'await for in' scope\n\t */\n\tforAwaitAsyncIterable?: AsyncIterableInfo;\n\n\t/**\n\t * is this stack has a propertyKey\n\t * @param propertyKey \n\t */\n\thas(propertyKey: PropertyKey): boolean;\n\n\t/**\n\t * get the first value for provided property key,\n\t * \n\t * will search current stack in all scope till find the first key, else undefined\n\t * @param propertyKey \n\t */\n\tget(propertyKey: PropertyKey): any;\n\n\t/**\n\t * set the value of `propertyKey` in its context provider with `value`.\n\t * else define it in the first scope 'local scope'\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean;\n\n\t/**\n\t * declare variable at last scope in the stack,\n\t * \n\t * @param propertyKey the name of property mey be string | number | symbol, \n\t * @param propertyValue if not exist will be initialize with 'undefined' value\n\t */\n\tdeclareVariable(propertyKey: PropertyKey, propertyValue?: any): any;\n\n\n\t/**\n\t * get context object of this provider,\n\t * search for the first context object that has `propertyKey`.\n\t * \n\t * search for the first context that have property key,\n\t * if not found will return the stack local scop as a default value\n\t * @param propertyKey the property key\n\t */\n\tfindScope<T extends Context>(propertyKey: PropertyKey): Scope<T>;\n\n\tresolveAwait(value: AwaitPromiseInfo): void;\n\n\t/**\n\t * get a reference to the last scope in this stack\n\t */\n\tlastScope<T extends Context>(): Scope<T>;\n\n\t/**\n\t * clear every thing after this scope, and even this scope\n\t * @param scope \n\t */\n\tclearTo<T extends Context>(scope: Scope<T>): boolean;\n\n\t/**\n\t * clear every thing after this scope, but not this scope\n\t * @param scope \n\t */\n\tclearTill<T extends Context>(scope: Scope<T>): boolean;\n\n\tpopScope<T extends Context>(): Scope<T>;\n\n\tremoveScope<T extends Context>(scope: Scope<T>): void;\n\n\tpushScope<T extends Context>(scope: Scope<T>): void;\n\n\tpushBlockScope<T extends Context>(): Scope<T>;\n\n\tpushBlockScopeFor<T extends Context>(context: T): Scope<T>;\n\n\tpushReactiveScope<T extends Context>(): ReactiveScope<T>;\n\n\tpushReactiveScopeFor<T extends Context>(context: T): ReactiveScope<T>;\n\n\t/**\n\t * create new stack instance with the same reference to the current scope array\n\t */\n\tcopyStack(): Stack;\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tdetach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\treattach(): void;\n\n\t/**\n\t * import module scope from another stack, by the help of ModuleScopeResolver.\n\t * \n\t * used with import statement\n\t */\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope;\n\n\t/**\n\t * get the current module for this stack.\n\t * \n\t * used with export statement\n\t */\n\tgetModule(): ModuleScope | undefined;\n\n\t/**\n\t * register action to do on destroy this stack\n\t */\n\tonDestroy(action: () => void): void;\n}\n\nexport class Stack implements Stack {\n\tstatic for(...contexts: Scope<Context>[]): Stack {\n\t\tif (contexts.length === 0) {\n\t\t\treturn new Stack();\n\t\t}\n\t\treturn new Stack(contexts.map(context => new Scope<Context>(context)));\n\t}\n\tstatic forScopes(...scopes: Scope<Context>[]): Stack {\n\t\tif (scopes.length === 0) {\n\t\t\tscopes.push(Scope.blockScope());\n\t\t}\n\t\treturn new Stack(scopes);\n\t}\n\tstatic moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<Context>[]) {\n\t\treturn new Stack(globalScopes, resolver, moduleSource);\n\t}\n\tawaitPromise: AwaitPromiseInfo[] = [];\n\tforAwaitAsyncIterable?: AsyncIterableInfo | undefined;\n\n\tprotected readonly stack: Array<Scope<any>>;\n\tprotected readonly moduleScope?: ModuleScope;\n\tprotected readonly moduleSource?: string;\n\tprotected readonly resolver?: ModuleScopeResolver;\n\n\tprotected readonly onDestroyActions: (() => void)[] = [];\n\n\tconstructor();\n\tconstructor(globalScope: Scope<Context>);\n\tconstructor(globalScope: Scope<Context>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(stack: Array<Scope<Context>>);\n\tconstructor(stack: Array<Scope<Context>>, resolver: ModuleScopeResolver, moduleSource: string);\n\n\tconstructor(globals?: Array<Scope<Context>> | Scope<Context>, resolver?: ModuleScopeResolver, moduleSource?: string) {\n\t\tif (Array.isArray(globals)) {\n\t\t\tthis.stack = globals;\n\t\t} else if (typeof globals == 'object') {\n\t\t\tthis.stack = [globals];\n\t\t} else {\n\t\t\tthis.stack = [];\n\t\t}\n\t\tif (resolver && moduleSource) {\n\t\t\tthis.resolver = resolver;\n\t\t\tthis.moduleSource = moduleSource;\n\t\t\t// init module scope for import and export\n\t\t\tthis.moduleScope = new ModuleScope(this.initModuleContext());\n\t\t\tthis.pushScope(this.moduleScope);\n\t\t\t// for the rest of module body\n\t\t\tthis.pushReactiveScope();\n\t\t} else {\n\t\t\t// not a module scope\n\t\t\tthis.pushBlockScope();\n\t\t}\n\t\tfinalizerRegister(this, this.onDestroyActions, this);\n\t}\n\tprivate initModuleContext(): ModuleContext {\n\t\tconst importFunc = (path: string) => {\n\t\t\treturn this.importModule(path);\n\t\t};\n\t\timportFunc.meta = {\n\t\t\turl: createRootURL(this.moduleSource!),\n\t\t\tresolve: (specified: string, parent?: string | URL): Promise<string> => {\n\t\t\t\treturn Promise.resolve(this.resolver!.resolveURL(specified, parent ?? importFunc.meta.url));\n\t\t\t}\n\t\t};\n\t\tconst im: ModuleImport & ((path: string) => Promise<any>) = importFunc as any;\n\t\treturn { import: im };\n\t}\n\thas(propertyKey: PropertyKey): boolean {\n\t\treturn this.stack.find(context => context.has(propertyKey)) ? true : false;\n\t}\n\tget(propertyKey: PropertyKey) {\n\t\treturn this.findScope<Context>(propertyKey).get(propertyKey);\n\t}\n\tset(propertyKey: PropertyKey, value: any, receiver?: any): boolean {\n\t\treturn this.findScope<Context>(propertyKey).set(propertyKey, value, receiver);\n\t}\n\tdeclareVariable(propertyKey: PropertyKey, propertyValue?: any) {\n\t\treturn this.lastScope<Context>().set(propertyKey, propertyValue);\n\t}\n\tfindScope<T extends Context>(propertyKey: PropertyKey): Scope<T> {\n\t\tlet lastIndex = this.stack.length;\n\t\twhile (lastIndex--) {\n\t\t\tconst scope = this.stack[lastIndex];\n\t\t\tif (scope.has(propertyKey)) {\n\t\t\t\treturn scope;\n\t\t\t}\n\t\t}\n\t\treturn this.lastScope();\n\t}\n\tresolveAwait(value: AwaitPromiseInfo): void {\n\t\tthis.awaitPromise.push(value);\n\t}\n\tpopScope<T extends Context>(): Scope<T> {\n\t\treturn this.stack.pop()!;\n\t}\n\tremoveScope<T extends Context>(scope: Scope<T>): void {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tthis.stack.splice(index, 1);\n\t}\n\tpushScope<T extends Context>(scope: Scope<T>): void {\n\t\tthis.stack.push(scope);\n\t}\n\tpushBlockScope<T extends Context>(): Scope<T> {\n\t\tconst scope = Scope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushBlockScopeFor<T extends Context>(context: T): Scope<T> {\n\t\tconst scope = Scope.for<T>(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScope<T extends Context>(): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.blockScope<T>();\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tpushReactiveScopeFor<T extends Context>(context: T): ReactiveScope<T> {\n\t\tconst scope = ReactiveScope.for(context);\n\t\tthis.stack.push(scope);\n\t\treturn scope;\n\t}\n\tlastScope<T extends Context>(): Scope<T> {\n\t\treturn this.stack[this.stack.length - 1];\n\t}\n\tclearTo<T extends Context>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index);\n\t\treturn true;\n\t}\n\tclearTill<T extends Context>(scope: Scope<T>): boolean {\n\t\tconst index = this.stack.lastIndexOf(scope);\n\t\tif (index === -1) {\n\t\t\treturn false;\n\t\t}\n\t\tthis.stack.splice(index + 1);\n\t\treturn true;\n\t}\n\tcopyStack(): Stack {\n\t\treturn new Stack(this.stack.slice(), this.resolver!, this.moduleSource!);\n\t}\n\tdetach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.detach());\n\t}\n\treattach(): void {\n\t\tthis.getReactiveScopeControls().forEach(scope => scope.reattach());\n\t}\n\tdetectChanges() {\n\t\tthis.getReactiveScope().forEach(scope => scope.detectChanges());\n\t}\n\tprivate getReactiveScopeControls(): ReactiveScopeControl<any>[] {\n\t\treturn this.stack.filter(scope => scope instanceof ReactiveScopeControl) as ReactiveScopeControl<any>[];\n\t}\n\tprivate getReactiveScope(): ReactiveScope<any>[] {\n\t\treturn this.stack.filter(scope => scope instanceof ReactiveScope) as ReactiveScope<any>[];\n\t}\n\timportModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (!this.resolver || !this.moduleScope) {\n\t\t\t// should o the parse and import the module\n\t\t\tthrow new Error('Module Resolver is undefined');\n\t\t}\n\t\treturn this.resolver.resolve(source, this.moduleScope, importCallOptions);\n\t}\n\tgetModule(): ModuleScope | undefined {\n\t\treturn this.moduleScope;\n\t}\n\n\tonDestroy(action: () => void): void {\n\t\tthis.onDestroyActions.push(action);\n\t}\n}\n\n\nexport interface ModuleScopeResolver {\n\tresolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;\n\tresolveURL(specified: string, parent: string | URL): string;\n}\n\nconst ROOT_URL = 'https://root';\nexport function createRootURL(source: string): URL {\n\treturn new URL(source, ROOT_URL);\n}\n\n\nexport interface ResolverConfig {\n\t/**\n\t * \n\t */\n\tallowImportExternal?: boolean;\n\n};\nexport class ModuleScopeResolver implements ModuleScopeResolver {\n\tprotected modules: [string, ModuleScope][] = [];\n\tconstructor(protected config?: ResolverConfig) { }\n\tregister(source: string, moduleScope: ModuleScope) {\n\t\tconst stackInfo = this.modules.find(tuple => tuple[0] == source && tuple[1] == moduleScope);\n\t\tif (stackInfo) {\n\t\t\tstackInfo[1] = moduleScope;\n\t\t} else {\n\t\t\tthis.modules.push([source, moduleScope]);\n\t\t}\n\t}\n\tresolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (this.isValidHTTPUrl(source)) {\n\t\t\treturn this.resolveExternalModule(source, importCallOptions);\n\t\t}\n\t\tif (source.startsWith('/')) {\n\t\t\treturn this.findScopeBySource(source, importCallOptions);\n\t\t}\n\t\tconst currentSource = this.findSourceByScope(moduleScope);\n\t\tconst absoluteUrl = this.resolveURL(source, currentSource);\n\t\treturn this.findScopeBySource(absoluteUrl, importCallOptions);\n\t}\n\tresolveURL(specified: string, parent: string | URL): string {\n\t\tconst currentUrl = parent instanceof URL ? parent.href : createRootURL(parent).href;\n\t\tconst importedUrl = new URL(specified, currentUrl).href;\n\t\tconst absoluteUrl = importedUrl.replace(ROOT_URL, '');\n\t\treturn absoluteUrl;\n\t}\n\tprotected findScopeBySource(source: string, importCallOptions?: ImportCallOptions): ModuleScope {\n\t\tif (importCallOptions?.assert?.type) {\n\t\t\tconst type = importCallOptions.assert.type;\n\t\t\tif (!source.endsWith(`.${type}`)) {\n\t\t\t\tthrow new Error(`Can't find module scope`);\n\t\t\t}\n\t\t}\n\t\tconst importedScope = this.modules.find(tuple => tuple[0] == source)?.[1];\n\t\tif (!importedScope) {\n\t\t\tthrow new Error(`Can't find module scope`);\n\t\t}\n\t\treturn importedScope;\n\t}\n\tprotected findSourceByScope(moduleScope: ModuleScope): string {\n\t\tconst importedSource = this.modules.find(tuple => tuple[1] == moduleScope)?.[0];\n\t\tif (!importedSource) {\n\t\t\tthrow new Error(`Can't resolve scope source`);\n\t\t}\n\t\treturn importedSource;\n\t}\n\tprotected resolveExternalModule(source: string, importCallOptions?: ImportCallOptions): WebModuleScope {\n\t\tif (!this.config?.allowImportExternal) {\n\t\t\tthrow new Error(`Error: Import External Module is not allowed.`);\n\t\t}\n\t\tconst webScope = new WebModuleScope()\n\t\tthis.modules.push([source, webScope]);\n\t\t// active later\n\t\t// import(source, importCallOptions)\n\t\timport(source).then(module => {\n\t\t\twebScope.updateContext(module);\n\t\t});\n\t\treturn webScope;\n\t}\n\tprotected readonly isValidHTTPUrl = (string: string) => {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(string);\n\t\t} catch (e) {\n\t\t\treturn false;\n\t\t}\n\t\treturn url.protocol === 'http:' || url.protocol === 'https:';\n\t}\n}\n"]}