@smartdoca/plugin-contracts 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.
@@ -0,0 +1,57 @@
1
+ # Licensing
2
+
3
+ [简体中文](LICENSING.zh-CN.md)
4
+
5
+ Doca uses a dual-licensing model for code owned by the Doca copyright holders.
6
+
7
+ ## Open-source license
8
+
9
+ Unless a file or package says otherwise, Doca-owned code in this repository is
10
+ available under the GNU Affero General Public License version 3 only
11
+ (`AGPL-3.0-only`). The full license text is in [LICENSE](LICENSE).
12
+
13
+ The AGPL permits commercial use. When its conditions apply, it requires the
14
+ corresponding source to remain available under the AGPL, including for modified
15
+ versions offered to users over a network. “Open source” and “free of charge” are
16
+ not the same thing, and the AGPL obligations do not depend on whether an operator
17
+ charges money.
18
+
19
+ ## Commercial license
20
+
21
+ Organizations that want to use Doca-owned code in a proprietary product without
22
+ the AGPL obligations may obtain a separate commercial license from the Doca
23
+ copyright holders. A commercial license exists only when both parties have
24
+ entered into a written agreement. This repository does not itself grant that
25
+ alternative license.
26
+
27
+ ## Packages and editors
28
+
29
+ The same licensing direction applies to Doca-owned packages and editors,
30
+ including the Doca plugin SDK and the Slate, presentation, spreadsheet,
31
+ Markdown, and canvas editor packages. Each released npm artifact must:
32
+
33
+ - carry an accurate license field and license notice;
34
+ - link to the public source repository and the exact source tag for that version;
35
+ - include the build scripts and dependency lock needed to produce the artifact;
36
+ - preserve all notices and license obligations of third-party components.
37
+
38
+ The historical archives under `vendor/` are development and recovery inputs.
39
+ They are not the long-term public distribution channel. Before the public
40
+ release, active editor dependencies must be rebuilt from their public tagged
41
+ sources, published to npm, and consumed by Doca through registry versions.
42
+
43
+ ## Third-party software and assets
44
+
45
+ The dual license covers only material for which the Doca copyright holders can
46
+ grant these rights. Third-party libraries, fonts, media, generated artifacts,
47
+ and other bundled material retain their own licenses. Their notices and source
48
+ or attribution requirements must be followed independently.
49
+
50
+ No trademark rights are granted by either the AGPL or this licensing summary.
51
+
52
+ ## Contributions
53
+
54
+ Dual licensing requires the project to retain the rights needed to offer future
55
+ commercial licenses. See [CONTRIBUTING.md](CONTRIBUTING.md) before submitting
56
+ code. This document is a project policy summary, not a substitute for the
57
+ license text or legal advice.
@@ -0,0 +1,48 @@
1
+ # 许可说明
2
+
3
+ [English](LICENSING.md)
4
+
5
+ Doca 对其版权所有者拥有权利的代码采用双许可模式。
6
+
7
+ ## 开源许可证
8
+
9
+ 除非文件或包中另有说明,本仓库内由 Doca 版权所有者拥有的代码默认采用
10
+ GNU Affero General Public License version 3 only(`AGPL-3.0-only`)。完整条款见
11
+ [LICENSE](LICENSE)。
12
+
13
+ AGPL 允许商业使用。当其条件适用时,分发软件或将修改后的版本作为网络服务提供给
14
+ 用户,需要继续按 AGPL 提供对应源码。是否收费并不是 AGPL 义务的判断条件,“开源”
15
+ 也不等于“免费”。
16
+
17
+ ## 商业许可证
18
+
19
+ 希望在闭源产品中使用 Doca 自研代码、且不希望承担 AGPL 义务的组织,可以向 Doca
20
+ 版权所有者申请单独的商业许可证。只有双方签署书面协议后,商业许可证才成立;本仓库
21
+ 本身不授予该替代许可证。
22
+
23
+ ## 子包与编辑器
24
+
25
+ 同一许可方向适用于 Doca 自研的子包和编辑器,包括插件 SDK,以及 Slate 富文本、
26
+ 演示文稿、表格、Markdown 和画板编辑器。每个正式发布的 npm 制品必须:
27
+
28
+ - 使用准确的许可证字段并携带许可证说明;
29
+ - 链接公开源码仓库以及与该版本精确对应的 Git tag;
30
+ - 提供生成该制品所需的构建脚本和依赖锁文件;
31
+ - 保留所有第三方组件要求的许可证及声明。
32
+
33
+ `vendor/` 中的历史压缩包是开发和恢复输入,不作为长期公开分发渠道。正式开源前,
34
+ 当前使用的编辑器依赖应从公开且已打 tag 的源码重新构建并发布到 npm,Doca 再改为
35
+ 使用 registry 版本。
36
+
37
+ ## 第三方软件与素材
38
+
39
+ 双许可只覆盖 Doca 版权所有者有权授予许可的内容。第三方库、字体、媒体、生成产物及
40
+ 其他随附内容继续适用各自许可证,其声明、源码提供或署名要求需要独立履行。
41
+
42
+ AGPL 和本文均不授予商标使用权。
43
+
44
+ ## 外部贡献
45
+
46
+ 双许可要求项目持续保有提供商业许可证所需的权利。提交代码前请阅读
47
+ [CONTRIBUTING.zh-CN.md](CONTRIBUTING.zh-CN.md)。本文只是项目政策摘要,不能替代
48
+ 许可证原文或专业法律意见。
@@ -0,0 +1,167 @@
1
+ export type JsonPrimitive = string | number | boolean | null;
2
+ export type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];
3
+ export interface JsonObject {
4
+ readonly [key: string]: JsonValue;
5
+ }
6
+ export type PluginRuntimePhase = "discover" | "initialize" | "mount" | "ready" | "dispose";
7
+ export type PluginRuntimeErrorCode = "INVALID_MANIFEST" | "INVALID_CONFIG" | "DUPLICATE_PLUGIN" | "MISSING_DEPENDENCY" | "INCOMPATIBLE_DEPENDENCY" | "DEPENDENCY_CYCLE" | "MISSING_INJECTION" | "DUPLICATE_PROVIDER" | "CONTRIBUTION_COLLISION" | "CONTEXT_DISPOSED" | "LIFECYCLE_FAILED";
8
+ export declare class PluginContractError extends Error {
9
+ readonly code: PluginRuntimeErrorCode;
10
+ readonly path: string;
11
+ readonly name = "PluginContractError";
12
+ constructor(code: PluginRuntimeErrorCode, message: string, path?: string);
13
+ }
14
+ export interface StringConfigSchema {
15
+ readonly type: "string";
16
+ readonly description?: string;
17
+ readonly default?: string;
18
+ readonly enum?: readonly string[];
19
+ readonly minLength?: number;
20
+ readonly maxLength?: number;
21
+ readonly pattern?: string;
22
+ }
23
+ export interface NumberConfigSchema {
24
+ readonly type: "number" | "integer";
25
+ readonly description?: string;
26
+ readonly default?: number;
27
+ readonly minimum?: number;
28
+ readonly maximum?: number;
29
+ }
30
+ export interface BooleanConfigSchema {
31
+ readonly type: "boolean";
32
+ readonly description?: string;
33
+ readonly default?: boolean;
34
+ }
35
+ export interface NullConfigSchema {
36
+ readonly type: "null";
37
+ readonly description?: string;
38
+ readonly default?: null;
39
+ }
40
+ export interface ArrayConfigSchema {
41
+ readonly type: "array";
42
+ readonly description?: string;
43
+ readonly default?: readonly JsonValue[];
44
+ readonly items: DocaConfigSchema;
45
+ readonly minItems?: number;
46
+ readonly maxItems?: number;
47
+ }
48
+ export interface ObjectConfigSchema {
49
+ readonly type: "object";
50
+ readonly description?: string;
51
+ readonly default?: JsonObject;
52
+ readonly properties?: Readonly<Record<string, DocaConfigSchema>>;
53
+ readonly required?: readonly string[];
54
+ readonly additionalProperties?: boolean;
55
+ }
56
+ /**
57
+ * The deliberately small configuration schema understood by the Doca runtime.
58
+ * It is not JSON Schema; unsupported keywords are rejected.
59
+ */
60
+ export type DocaConfigSchema = StringConfigSchema | NumberConfigSchema | BooleanConfigSchema | NullConfigSchema | ArrayConfigSchema | ObjectConfigSchema;
61
+ export interface PluginDependency {
62
+ readonly id: string;
63
+ /** Supported forms are `*`, an exact semver, `^x.y.z`, or `~x.y.z`. */
64
+ readonly range: string;
65
+ readonly optional?: boolean;
66
+ }
67
+ export interface PluginManifest {
68
+ readonly schemaVersion: 1;
69
+ readonly id: string;
70
+ readonly version: string;
71
+ /** Doca SDK versions supported by this package. Uses the same range subset as dependencies. */
72
+ readonly sdkRange?: string;
73
+ readonly displayName: string;
74
+ readonly description?: string;
75
+ readonly dependencies?: readonly PluginDependency[];
76
+ readonly config?: ObjectConfigSchema;
77
+ readonly contributions?: readonly PluginContributionDeclaration[];
78
+ }
79
+ export interface PluginContributionDeclaration {
80
+ readonly id: string;
81
+ readonly kind: string;
82
+ readonly target?: "server" | "web" | "mobile";
83
+ }
84
+ export interface DocaPluginPackage {
85
+ readonly package: string;
86
+ readonly enabled?: boolean;
87
+ readonly config?: JsonObject;
88
+ readonly targets?: readonly ("server" | "web" | "mobile")[];
89
+ }
90
+ export interface DocaSystemConfig {
91
+ readonly plugins: readonly DocaPluginPackage[];
92
+ }
93
+ export declare function validatePluginManifest(input: unknown): PluginManifest;
94
+ export declare function validatePluginConfig<T extends JsonObject = JsonObject>(manifest: PluginManifest, input: unknown): T;
95
+ export declare function satisfiesPluginVersion(version: string, range: string): boolean;
96
+ export type MaybePromise<T> = T | Promise<T>;
97
+ export type EffectCleanup = () => MaybePromise<void>;
98
+ export type EffectDisposer = () => Promise<void>;
99
+ declare const serviceType: unique symbol;
100
+ export interface ServiceToken<T> {
101
+ readonly id: string;
102
+ readonly [serviceType]?: T;
103
+ }
104
+ export type DispatchMode = "emit" | "parallel" | "serial" | "bail" | "waterfall";
105
+ export type NonWaterfallDispatchMode = Exclude<DispatchMode, "waterfall">;
106
+ export type WaterfallNext<Result> = () => Result;
107
+ declare const eventPayload: unique symbol;
108
+ declare const eventResult: unique symbol;
109
+ export interface EventToken<Payload, Result = void, Mode extends DispatchMode = "emit"> {
110
+ readonly id: string;
111
+ readonly mode: Mode;
112
+ readonly [eventPayload]?: Payload;
113
+ readonly [eventResult]?: Result;
114
+ }
115
+ export type EventHandler<Payload, Result, Mode extends DispatchMode> = Mode extends "waterfall" ? (payload: Payload, next: WaterfallNext<Result>) => Result : Mode extends "bail" ? (payload: Payload) => Result | false | null | undefined : Mode extends "serial" ? (payload: Payload) => MaybePromise<Result | false | null | undefined> : (payload: Payload) => MaybePromise<Result>;
116
+ export type DispatchResult<Result, Mode extends DispatchMode> = Mode extends "emit" ? void : Mode extends "parallel" ? Promise<void> : Mode extends "serial" ? Promise<Awaited<Result> | undefined> : Mode extends "bail" ? Result | undefined : Result;
117
+ declare const contributionType: unique symbol;
118
+ export interface ContributionPoint<T> {
119
+ readonly id: string;
120
+ readonly [contributionType]?: T;
121
+ }
122
+ export interface ContributionRecord<T> {
123
+ readonly point: string;
124
+ readonly id: string;
125
+ readonly pluginId: string;
126
+ readonly value: T;
127
+ }
128
+ export interface DocaContributionRegistry {
129
+ register<T>(point: ContributionPoint<T>, id: string, value: T): EffectDisposer;
130
+ get<T>(point: ContributionPoint<T>, id: string): ContributionRecord<T> | undefined;
131
+ list<T>(point: ContributionPoint<T>): readonly ContributionRecord<T>[];
132
+ }
133
+ export interface DocaContext {
134
+ readonly scopeId: string;
135
+ readonly disposed: boolean;
136
+ provide<T>(token: ServiceToken<T>, value: T): EffectDisposer;
137
+ inject<T>(token: ServiceToken<T>): T;
138
+ injectOptional<T>(token: ServiceToken<T>): T | undefined;
139
+ has(token: ServiceToken<unknown>): boolean;
140
+ effect(setup: () => EffectCleanup | void): EffectDisposer;
141
+ effectAsync(setup: () => Promise<EffectCleanup | void>): Promise<EffectDisposer>;
142
+ child(scopeId?: string): DocaContext;
143
+ on<Payload, Result, Mode extends DispatchMode>(event: EventToken<Payload, Result, Mode>, handler: EventHandler<Payload, Result, Mode>): EffectDisposer;
144
+ dispatch<Payload, Result>(event: EventToken<Payload, Result, "waterfall">, payload: Payload, next: WaterfallNext<Result>): Result;
145
+ dispatch<Payload, Result, Mode extends NonWaterfallDispatchMode>(event: EventToken<Payload, Result, Mode>, payload: Payload): DispatchResult<Result, Mode>;
146
+ dispose(): Promise<void>;
147
+ }
148
+ export interface PluginLifecycleContext<Config extends JsonObject = JsonObject> extends DocaContext {
149
+ readonly manifest: PluginManifest;
150
+ readonly config: Config;
151
+ readonly contributions: DocaContributionRegistry;
152
+ }
153
+ export interface PluginInjections {
154
+ readonly required?: readonly ServiceToken<unknown>[];
155
+ readonly optional?: readonly ServiceToken<unknown>[];
156
+ }
157
+ export interface DocaPlugin<Config extends JsonObject = JsonObject> {
158
+ readonly manifest: PluginManifest;
159
+ readonly injections?: PluginInjections;
160
+ discover?(context: PluginLifecycleContext<Config>): MaybePromise<void>;
161
+ /** Runs on every start, including when the package version has not changed. */
162
+ initialize?(context: PluginLifecycleContext<Config>): MaybePromise<void>;
163
+ mount?(context: PluginLifecycleContext<Config>): MaybePromise<void>;
164
+ ready?(context: PluginLifecycleContext<Config>): MaybePromise<void>;
165
+ dispose?(context: PluginLifecycleContext<Config>): MaybePromise<void>;
166
+ }
167
+ export {};