@no22/dison 1.0.0 → 1.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/README.md +36 -9
- package/dist/analysis.d.ts +10 -0
- package/dist/analysis.d.ts.map +1 -1
- package/dist/analysis.js +109 -4
- package/dist/analysis.js.map +1 -1
- package/dist/cli.js +16 -2
- package/dist/cli.js.map +1 -1
- package/dist/codegen.d.ts +14 -1
- package/dist/codegen.d.ts.map +1 -1
- package/dist/codegen.js +100 -19
- package/dist/codegen.js.map +1 -1
- package/dist/collisions.d.ts +33 -0
- package/dist/collisions.d.ts.map +1 -1
- package/dist/collisions.js +180 -2
- package/dist/collisions.js.map +1 -1
- package/dist/core.d.ts +34 -10
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +80 -15
- package/dist/core.js.map +1 -1
- package/dist/generated-runtime.d.ts +3 -3
- package/dist/generated-runtime.d.ts.map +1 -1
- package/dist/generated-runtime.js +12 -4
- package/dist/generated-runtime.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +25 -13
- package/dist/runtime.js.map +1 -1
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -16,11 +16,15 @@
|
|
|
16
16
|
// - 複数ファイルにまたがって同名クラスが存在しても、参照そのものが
|
|
17
17
|
// キーになるため衝突しない(docs/multi-file-support.md参照)。
|
|
18
18
|
//
|
|
19
|
-
// TYPE_BINDINGS(bind
|
|
20
|
-
// interface
|
|
21
|
-
// DI_REGISTRY
|
|
22
|
-
//
|
|
23
|
-
//
|
|
19
|
+
// TYPE_BINDINGS(bind用)のキーは、型が具象クラスなら実体参照(Function)、
|
|
20
|
+
// それ以外(interface/型エイリアス/ジェネリクス)なら型名の文字列を使う。
|
|
21
|
+
// 具象クラスの実体キー化はDI_REGISTRYと同じ発想で、複数ファイルにまたがる
|
|
22
|
+
// 同名クラスが衝突しなくなる(手動tokenなしで自動的に別の実体として区別される。
|
|
23
|
+
// どの型を実体キーにするかの判定はcodegen/collisionsが担う。
|
|
24
|
+
// docs/type-identity-matching.md)。bindの左辺がinterface/型エイリアスの場合は
|
|
25
|
+
// 実行時に値が無いため実体参照できず、文字列キーのまま。複数ファイルに
|
|
26
|
+
// またがる同名interface/型エイリアスの衝突は "as <トークン>" で回避する
|
|
27
|
+
// (docs/bind-interface-token.md)。
|
|
24
28
|
export function generateRuntimeDeclarations(exportKeyword) {
|
|
25
29
|
return (`// Global dependency registry (per-property override).\n` +
|
|
26
30
|
`// Keying on the class itself (not its name) lets tsc catch a typo in the\n` +
|
|
@@ -38,26 +42,34 @@ export function generateRuntimeDeclarations(exportKeyword) {
|
|
|
38
42
|
` return DI_REGISTRY.get(cls)?.[prop];\n` +
|
|
39
43
|
`}\n\n` +
|
|
40
44
|
`// Global type-replacement registry (bind).\n` +
|
|
41
|
-
`// The key is
|
|
42
|
-
`//
|
|
43
|
-
`// name
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
`// The key is one of:\n` +
|
|
46
|
+
`// - The class itself (Function). When a bind/injectable type is a concrete\n` +
|
|
47
|
+
`// class, the class value (not its name string) is used as the key (same\n` +
|
|
48
|
+
`// idea as DI_REGISTRY). Same-named classes across files no longer collide\n` +
|
|
49
|
+
`// as a result (no manual token needed; with string keys, unrelated\n` +
|
|
50
|
+
`// same-named classes used to pollute each other).\n` +
|
|
51
|
+
`// - A type-name string. Used for interfaces/type aliases (no runtime value)\n` +
|
|
52
|
+
`// and generics with concrete type arguments (Repository<User>).\n` +
|
|
53
|
+
`// - A Symbol explicitly given via an "as <token>" clause (to avoid collisions\n` +
|
|
54
|
+
`// between same-named interfaces/type aliases across files. docs/bind-interface-token.md).\n` +
|
|
55
|
+
`${exportKeyword}const TYPE_BINDINGS = new Map<string | symbol | Function, () => any>();\n` +
|
|
56
|
+
`const _resolvingTypeBindings = new Set<string | symbol | Function>();\n\n` +
|
|
46
57
|
`// bindType<T> takes T as an explicit type argument, so tsc raises a\n` +
|
|
47
58
|
`// compile error if the replacement factory isn't compatible with the\n` +
|
|
48
59
|
`// original type. T may be an interface or type alias (used only as a\n` +
|
|
49
60
|
`// type argument).\n` +
|
|
50
|
-
`${exportKeyword}function bindType<T>(typeKey: string | symbol, factory: () => T): void {\n` +
|
|
61
|
+
`${exportKeyword}function bindType<T>(typeKey: string | symbol | Function, factory: () => T): void {\n` +
|
|
51
62
|
` TYPE_BINDINGS.set(typeKey, factory);\n` +
|
|
52
63
|
`}\n\n` +
|
|
53
64
|
`// Resolves a value by recursively walking TYPE_BINDINGS. bind chains\n` +
|
|
54
65
|
`// (e.g. bind A = B; bind B = C; makes resolving A eventually reach C).\n` +
|
|
55
66
|
`// A cycle (A -> B -> A) raises a clear error instead of a stack overflow.\n` +
|
|
56
|
-
`${exportKeyword}function resolveType<T>(typeKey: string | symbol, defaultFactory: () => T): T {\n` +
|
|
67
|
+
`${exportKeyword}function resolveType<T>(typeKey: string | symbol | Function, defaultFactory: () => T): T {\n` +
|
|
57
68
|
` const bound = TYPE_BINDINGS.get(typeKey);\n` +
|
|
58
69
|
` if (!bound) return defaultFactory();\n` +
|
|
59
70
|
` if (_resolvingTypeBindings.has(typeKey)) {\n` +
|
|
60
|
-
`
|
|
71
|
+
` const label = typeof typeKey === 'function' ? (typeKey.name || '<anonymous class>') : String(typeKey);\n` +
|
|
72
|
+
` throw new Error('Detected a circular "bind" reference ("' + label + '"). The bind chain loops back on itself.');\n` +
|
|
61
73
|
` }\n` +
|
|
62
74
|
` _resolvingTypeBindings.add(typeKey);\n` +
|
|
63
75
|
` try {\n` +
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,gBAAgB;AAChB,wEAAwE;AAExE,6DAA6D;AAC7D,oEAAoE;AACpE,2CAA2C;AAC3C,sCAAsC;AACtC,EAAE;AACF,kDAAkD;AAClD,oCAAoC;AACpC,gDAAgD;AAChD,yCAAyC;AACzC,wCAAwC;AACxC,gDAAgD;AAChD,mBAAmB;AACnB,sCAAsC;AACtC,kDAAkD;AAClD,EAAE;AACF,
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,gBAAgB;AAChB,wEAAwE;AAExE,6DAA6D;AAC7D,oEAAoE;AACpE,2CAA2C;AAC3C,sCAAsC;AACtC,EAAE;AACF,kDAAkD;AAClD,oCAAoC;AACpC,gDAAgD;AAChD,yCAAyC;AACzC,wCAAwC;AACxC,gDAAgD;AAChD,mBAAmB;AACnB,sCAAsC;AACtC,kDAAkD;AAClD,EAAE;AACF,oDAAoD;AACpD,4CAA4C;AAC5C,4CAA4C;AAC5C,4CAA4C;AAC5C,yCAAyC;AACzC,+DAA+D;AAC/D,qCAAqC;AACrC,+CAA+C;AAC/C,kCAAkC;AAClC,MAAM,UAAU,2BAA2B,CAAC,aAA6B;IACvE,OAAO,CACL,0DAA0D;QAC1D,6EAA6E;QAC7E,gEAAgE;QAChE,GAAG,aAAa,6EAA6E;QAC7F,GAAG,aAAa,sFAAsF;QACtG,uCAAuC;QACvC,mBAAmB;QACnB,mBAAmB;QACnB,oCAAoC;QACpC,OAAO;QACP,4BAA4B;QAC5B,OAAO;QACP,GAAG,aAAa,gFAAgF;QAChG,0CAA0C;QAC1C,OAAO;QACP,+CAA+C;QAC/C,yBAAyB;QACzB,iFAAiF;QACjF,gFAAgF;QAChF,kFAAkF;QAClF,2EAA2E;QAC3E,0DAA0D;QAC1D,kFAAkF;QAClF,wEAAwE;QACxE,oFAAoF;QACpF,kGAAkG;QAClG,GAAG,aAAa,2EAA2E;QAC3F,2EAA2E;QAC3E,wEAAwE;QACxE,yEAAyE;QACzE,yEAAyE;QACzE,sBAAsB;QACtB,GAAG,aAAa,uFAAuF;QACvG,0CAA0C;QAC1C,OAAO;QACP,yEAAyE;QACzE,2EAA2E;QAC3E,8EAA8E;QAC9E,GAAG,aAAa,8FAA8F;QAC9G,+CAA+C;QAC/C,0CAA0C;QAC1C,gDAAgD;QAChD,8GAA8G;QAC9G,wHAAwH;QACxH,OAAO;QACP,0CAA0C;QAC1C,WAAW;QACX,uBAAuB;QACvB,iBAAiB;QACjB,+CAA+C;QAC/C,OAAO;QACP,KAAK,CACN,CAAC;AACJ,CAAC;AAED,oDAAoD;AACpD,uDAAuD;AACvD,uDAAuD;AACvD,yDAAyD;AACzD,MAAM,CAAC,MAAM,2BAA2B,GACtC,0CAA0C;IAC1C,yEAAyE;IACzE,yCAAyC;IACzC,6FAA6F;IAC7F,2BAA2B,CAAC,SAAS,CAAC,CAAC"}
|
package/package.json
CHANGED