@formfeed/devkit 0.1.0 → 0.3.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/index.cjs +963 -42
- package/index.js +941 -38
- package/package.json +3 -3
- package/types/index.d.cts +12 -3
- package/types/index.d.ts +12 -3
- package/types/lib/brand.d.cts +14 -0
- package/types/lib/brand.d.ts +14 -0
- package/types/lib/files.d.cts +32 -0
- package/types/lib/files.d.ts +32 -0
- package/types/lib/local-render.d.cts +39 -3
- package/types/lib/local-render.d.ts +39 -3
- package/types/lib/partials.d.cts +19 -0
- package/types/lib/partials.d.ts +19 -0
- package/types/lib/project-config.d.cts +16 -0
- package/types/lib/project-config.d.ts +16 -0
- package/types/lib/project.d.cts +83 -7
- package/types/lib/project.d.ts +83 -7
- package/types/lib/redact.d.cts +19 -0
- package/types/lib/redact.d.ts +19 -0
- package/types/lib/types/emit-python.d.cts +6 -0
- package/types/lib/types/emit-python.d.ts +6 -0
- package/types/lib/types/emit-ts.d.cts +10 -0
- package/types/lib/types/emit-ts.d.ts +10 -0
- package/types/lib/types/index.d.cts +15 -0
- package/types/lib/types/index.d.ts +15 -0
- package/types/lib/types/model.d.cts +81 -0
- package/types/lib/types/model.d.ts +81 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formfeed/devkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Formfeed template folders, project config and local rendering, shared by the CLI and @formfeed/testing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
],
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@formfeed/engine": "0.
|
|
34
|
-
"@formfeed/sdk": "0.
|
|
33
|
+
"@formfeed/engine": "0.3.0",
|
|
34
|
+
"@formfeed/sdk": "0.3.0"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"formfeed",
|
package/types/index.d.cts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
export { DevkitError } from './lib/errors.cjs';
|
|
2
2
|
export { defaultProjectConfig, findProject, loadProject, projectAround, writeProjectConfig } from './lib/project-config.cjs';
|
|
3
3
|
export type { Project, ProjectConfig } from './lib/project-config.cjs';
|
|
4
|
-
export { contentHash, defaultData, listTemplateSlugs, partialResolver, readState, readTemplate, recordSync, templateDir, titleFromSlug, versionPayload, writeState, writeTemplate, } from './lib/project.cjs';
|
|
5
|
-
export type { LocalTemplate, ProjectState, TemplateMeta, TemplateState } from './lib/project.cjs';
|
|
6
|
-
export {
|
|
4
|
+
export { contentHash, defaultData, listTemplateSlugs, officeVersionPayload, partialContentHash, partialResolver, readState, readTemplate, recordSharedPartial, recordSync, sharedPartialNames, sharedPartialPath, templateDir, templateFileName, titleFromSlug, versionPayload, writePartials, writeState, writeTemplate, } from './lib/project.cjs';
|
|
5
|
+
export type { LocalOfficeFile, LocalTemplate, ProjectState, SharedPartialState, TemplateMeta, TemplateState } from './lib/project.cjs';
|
|
6
|
+
export { brandFromJson, brandPath, readBrand, writeBrand } from './lib/brand.cjs';
|
|
7
|
+
export { collectPartials } from './lib/partials.cjs';
|
|
8
|
+
export type { CollectedPartials } from './lib/partials.cjs';
|
|
9
|
+
export { diagnose, officeSnapshot, prettyXml, previewDocument, renderContext, renderLocal, renderOfficeLocal } from './lib/local-render.cjs';
|
|
10
|
+
export type { LocalDiagnostic, OfficeLocalOptions } from './lib/local-render.cjs';
|
|
11
|
+
export { contentTypeFor, listLocalFiles, localFilePath, sha256File, writeLocalFile } from './lib/files.cjs';
|
|
12
|
+
export type { LocalFile, LocalFileListing } from './lib/files.cjs';
|
|
7
13
|
export type { LocalRenderOptions } from './lib/local-render.cjs';
|
|
14
|
+
export { parseRedactPath, redactData, redactString } from './lib/redact.cjs';
|
|
15
|
+
export { defaultTypesFile, generateTypes, localTypeSource } from './lib/types/index.cjs';
|
|
16
|
+
export type { SchemaOrigin, TypeScriptOptions, TypeSource, TypesLanguage } from './lib/types/index.cjs';
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
export { DevkitError } from './lib/errors.js';
|
|
2
2
|
export { defaultProjectConfig, findProject, loadProject, projectAround, writeProjectConfig } from './lib/project-config.js';
|
|
3
3
|
export type { Project, ProjectConfig } from './lib/project-config.js';
|
|
4
|
-
export { contentHash, defaultData, listTemplateSlugs, partialResolver, readState, readTemplate, recordSync, templateDir, titleFromSlug, versionPayload, writeState, writeTemplate, } from './lib/project.js';
|
|
5
|
-
export type { LocalTemplate, ProjectState, TemplateMeta, TemplateState } from './lib/project.js';
|
|
6
|
-
export {
|
|
4
|
+
export { contentHash, defaultData, listTemplateSlugs, officeVersionPayload, partialContentHash, partialResolver, readState, readTemplate, recordSharedPartial, recordSync, sharedPartialNames, sharedPartialPath, templateDir, templateFileName, titleFromSlug, versionPayload, writePartials, writeState, writeTemplate, } from './lib/project.js';
|
|
5
|
+
export type { LocalOfficeFile, LocalTemplate, ProjectState, SharedPartialState, TemplateMeta, TemplateState } from './lib/project.js';
|
|
6
|
+
export { brandFromJson, brandPath, readBrand, writeBrand } from './lib/brand.js';
|
|
7
|
+
export { collectPartials } from './lib/partials.js';
|
|
8
|
+
export type { CollectedPartials } from './lib/partials.js';
|
|
9
|
+
export { diagnose, officeSnapshot, prettyXml, previewDocument, renderContext, renderLocal, renderOfficeLocal } from './lib/local-render.js';
|
|
10
|
+
export type { LocalDiagnostic, OfficeLocalOptions } from './lib/local-render.js';
|
|
11
|
+
export { contentTypeFor, listLocalFiles, localFilePath, sha256File, writeLocalFile } from './lib/files.js';
|
|
12
|
+
export type { LocalFile, LocalFileListing } from './lib/files.js';
|
|
7
13
|
export type { LocalRenderOptions } from './lib/local-render.js';
|
|
14
|
+
export { parseRedactPath, redactData, redactString } from './lib/redact.js';
|
|
15
|
+
export { defaultTypesFile, generateTypes, localTypeSource } from './lib/types/index.js';
|
|
16
|
+
export type { SchemaOrigin, TypeScriptOptions, TypeSource, TypesLanguage } from './lib/types/index.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type BrandContext } from '@formfeed/engine';
|
|
2
|
+
import type { Project } from './project-config.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* The organisation's brand kit as `formfeed brand pull` stores it (spec 18 §8): the `GET /brand`
|
|
5
|
+
* response, kept whole in `.formfeed/brand.json` so page defaults and the timestamp survive. Local
|
|
6
|
+
* renders take the template's `brand` from it; without the file they get the empty kit, which is
|
|
7
|
+
* also what an organisation that has set nothing renders with.
|
|
8
|
+
*/
|
|
9
|
+
export declare const brandPath: (project: Project) => string;
|
|
10
|
+
/** The `brand` a template sees, from a stored `GET /brand` body; unknown or malformed fields fall back to the empty kit. */
|
|
11
|
+
export declare function brandFromJson(json: unknown): BrandContext;
|
|
12
|
+
export declare function readBrand(project: Project): BrandContext;
|
|
13
|
+
/** Stores a `GET /brand` body; returns the file path. */
|
|
14
|
+
export declare function writeBrand(project: Project, brand: unknown): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type BrandContext } from '@formfeed/engine';
|
|
2
|
+
import type { Project } from './project-config.js';
|
|
3
|
+
/**
|
|
4
|
+
* The organisation's brand kit as `formfeed brand pull` stores it (spec 18 §8): the `GET /brand`
|
|
5
|
+
* response, kept whole in `.formfeed/brand.json` so page defaults and the timestamp survive. Local
|
|
6
|
+
* renders take the template's `brand` from it; without the file they get the empty kit, which is
|
|
7
|
+
* also what an organisation that has set nothing renders with.
|
|
8
|
+
*/
|
|
9
|
+
export declare const brandPath: (project: Project) => string;
|
|
10
|
+
/** The `brand` a template sees, from a stored `GET /brand` body; unknown or malformed fields fall back to the empty kit. */
|
|
11
|
+
export declare function brandFromJson(json: unknown): BrandContext;
|
|
12
|
+
export declare function readBrand(project: Project): BrandContext;
|
|
13
|
+
/** Stores a `GET /brand` body; returns the file path. */
|
|
14
|
+
export declare function writeBrand(project: Project, brand: unknown): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Project } from './project-config.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* The project's `files/` folder: the local copy of the workspace file library (spec 04 §2.3). A
|
|
4
|
+
* file's path below the folder is its library name, so `files/brand/logo.png` is what a template
|
|
5
|
+
* reaches with `asset('brand/logo.png')`, locally in `formfeed dev` and remotely after `files push`.
|
|
6
|
+
*/
|
|
7
|
+
export interface LocalFile {
|
|
8
|
+
/** The library name: the path below the files folder, with `/`. */
|
|
9
|
+
name: string;
|
|
10
|
+
path: string;
|
|
11
|
+
bytes: number;
|
|
12
|
+
sha256: string;
|
|
13
|
+
/** From the extension; null for a type the library does not take. */
|
|
14
|
+
contentType: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface LocalFileListing {
|
|
17
|
+
files: LocalFile[];
|
|
18
|
+
/** Paths the library would refuse: an unusable name, an unknown type, too large or empty. */
|
|
19
|
+
skipped: Array<{
|
|
20
|
+
path: string;
|
|
21
|
+
reason: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/** The content type the library stores for a name, going by its extension. */
|
|
25
|
+
export declare function contentTypeFor(name: string): string | null;
|
|
26
|
+
export declare function sha256File(bytes: Uint8Array): string;
|
|
27
|
+
/** Every file below the files folder, with the ones the library would refuse listed apart. */
|
|
28
|
+
export declare function listLocalFiles(project: Project): LocalFileListing;
|
|
29
|
+
/** The path of a library name inside the files folder; refuses a name that would leave it. */
|
|
30
|
+
export declare function localFilePath(project: Project, name: string): string;
|
|
31
|
+
/** Writes a pulled file below the files folder, creating folders for names like `brand/logo.png`. */
|
|
32
|
+
export declare function writeLocalFile(project: Project, name: string, bytes: Uint8Array): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Project } from './project-config.js';
|
|
2
|
+
/**
|
|
3
|
+
* The project's `files/` folder: the local copy of the workspace file library (spec 04 §2.3). A
|
|
4
|
+
* file's path below the folder is its library name, so `files/brand/logo.png` is what a template
|
|
5
|
+
* reaches with `asset('brand/logo.png')`, locally in `formfeed dev` and remotely after `files push`.
|
|
6
|
+
*/
|
|
7
|
+
export interface LocalFile {
|
|
8
|
+
/** The library name: the path below the files folder, with `/`. */
|
|
9
|
+
name: string;
|
|
10
|
+
path: string;
|
|
11
|
+
bytes: number;
|
|
12
|
+
sha256: string;
|
|
13
|
+
/** From the extension; null for a type the library does not take. */
|
|
14
|
+
contentType: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface LocalFileListing {
|
|
17
|
+
files: LocalFile[];
|
|
18
|
+
/** Paths the library would refuse: an unusable name, an unknown type, too large or empty. */
|
|
19
|
+
skipped: Array<{
|
|
20
|
+
path: string;
|
|
21
|
+
reason: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/** The content type the library stores for a name, going by its extension. */
|
|
25
|
+
export declare function contentTypeFor(name: string): string | null;
|
|
26
|
+
export declare function sha256File(bytes: Uint8Array): string;
|
|
27
|
+
/** Every file below the files folder, with the ones the library would refuse listed apart. */
|
|
28
|
+
export declare function listLocalFiles(project: Project): LocalFileListing;
|
|
29
|
+
/** The path of a library name inside the files folder; refuses a name that would leave it. */
|
|
30
|
+
export declare function localFilePath(project: Project, name: string): string;
|
|
31
|
+
/** Writes a pulled file below the files folder, creating folders for names like `brand/logo.png`. */
|
|
32
|
+
export declare function writeLocalFile(project: Project, name: string, bytes: Uint8Array): string;
|
|
@@ -1,13 +1,49 @@
|
|
|
1
|
-
import { type AssembleVendor, type Diagnostic, type RenderContext, type RenderedDocument } from '@formfeed/engine';
|
|
1
|
+
import { type AssembleVendor, type BrandContext, type Diagnostic, type OfficeImageHost, type OfficeRenderResult, type RenderContext, type RenderedDocument } from '@formfeed/engine';
|
|
2
2
|
import type { Project } from './project-config.cjs';
|
|
3
3
|
import { type LocalTemplate } from './project.cjs';
|
|
4
|
+
/**
|
|
5
|
+
* A finding of `diagnose`. Word and PowerPoint findings name the part and paragraph instead of a line
|
|
6
|
+
* (their `range` is 1:1), because a line of the extracted text means nothing in the document.
|
|
7
|
+
*/
|
|
8
|
+
export type LocalDiagnostic = Diagnostic & {
|
|
9
|
+
part?: string;
|
|
10
|
+
paragraph?: number;
|
|
11
|
+
};
|
|
4
12
|
/** The same diagnostics the editor shows: analysis of the body against the sample data plus compile errors. */
|
|
5
|
-
export declare function diagnose(tpl: LocalTemplate, sampleData: unknown):
|
|
6
|
-
export
|
|
13
|
+
export declare function diagnose(tpl: LocalTemplate, sampleData: unknown): LocalDiagnostic[];
|
|
14
|
+
export interface OfficeLocalOptions {
|
|
15
|
+
locale?: string;
|
|
16
|
+
/** Where `asset()` resolves; the workspace library's CDN base for a document that leaves the machine. */
|
|
17
|
+
assetBaseUrl?: string;
|
|
18
|
+
brand?: BrandContext;
|
|
19
|
+
/** Loads and draws pictures and codes; without one, only PNG and JPEG data URLs are placed. */
|
|
20
|
+
images?: OfficeImageHost;
|
|
21
|
+
/** For snapshots: the source of the engine's placeholder nonce, so repeated runs fill alike. */
|
|
22
|
+
random?: () => number;
|
|
23
|
+
}
|
|
24
|
+
/** Fills a Word or PowerPoint template with the shared engine, as the render-worker does. */
|
|
25
|
+
export declare function renderOfficeLocal(project: Project, tpl: LocalTemplate, data: unknown, options?: OfficeLocalOptions): Promise<OfficeRenderResult>;
|
|
26
|
+
/**
|
|
27
|
+
* The filled parts of a Word or PowerPoint document as readable text for snapshots: each part's XML,
|
|
28
|
+
* one element per line and indented, text kept beside its element, under a `--- <part> ---` line.
|
|
29
|
+
*/
|
|
30
|
+
export declare function officeSnapshot(filled: Uint8Array): string;
|
|
31
|
+
/** Indents XML one element per line; text and the closing tag stay on the line of their element. */
|
|
32
|
+
export declare function prettyXml(xml: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* `assetBaseUrl` is where `asset()` and relative image paths resolve: the dev server's `/files`
|
|
35
|
+
* locally, the workspace library's CDN base when the document goes to the API. Without it the
|
|
36
|
+
* references stay relative, which keeps snapshots independent of any host.
|
|
37
|
+
*/
|
|
38
|
+
export declare function renderContext(project: Project, tpl: LocalTemplate, assetBaseUrl?: string, brand?: BrandContext): RenderContext;
|
|
7
39
|
export interface LocalRenderOptions {
|
|
8
40
|
mode: 'preview' | 'print';
|
|
9
41
|
locale?: string;
|
|
10
42
|
vendor?: AssembleVendor;
|
|
43
|
+
/** Where `asset()` and relative image paths resolve (see `renderContext`). */
|
|
44
|
+
assetBaseUrl?: string;
|
|
45
|
+
/** The template's `brand`; `.formfeed/brand.json` (`readBrand`) when left out. */
|
|
46
|
+
brand?: BrandContext;
|
|
11
47
|
}
|
|
12
48
|
/** Assembles the complete document with the shared engine; no browser involved. */
|
|
13
49
|
export declare function renderLocal(project: Project, tpl: LocalTemplate, data: unknown, options: LocalRenderOptions): Promise<RenderedDocument>;
|
|
@@ -1,13 +1,49 @@
|
|
|
1
|
-
import { type AssembleVendor, type Diagnostic, type RenderContext, type RenderedDocument } from '@formfeed/engine';
|
|
1
|
+
import { type AssembleVendor, type BrandContext, type Diagnostic, type OfficeImageHost, type OfficeRenderResult, type RenderContext, type RenderedDocument } from '@formfeed/engine';
|
|
2
2
|
import type { Project } from './project-config.js';
|
|
3
3
|
import { type LocalTemplate } from './project.js';
|
|
4
|
+
/**
|
|
5
|
+
* A finding of `diagnose`. Word and PowerPoint findings name the part and paragraph instead of a line
|
|
6
|
+
* (their `range` is 1:1), because a line of the extracted text means nothing in the document.
|
|
7
|
+
*/
|
|
8
|
+
export type LocalDiagnostic = Diagnostic & {
|
|
9
|
+
part?: string;
|
|
10
|
+
paragraph?: number;
|
|
11
|
+
};
|
|
4
12
|
/** The same diagnostics the editor shows: analysis of the body against the sample data plus compile errors. */
|
|
5
|
-
export declare function diagnose(tpl: LocalTemplate, sampleData: unknown):
|
|
6
|
-
export
|
|
13
|
+
export declare function diagnose(tpl: LocalTemplate, sampleData: unknown): LocalDiagnostic[];
|
|
14
|
+
export interface OfficeLocalOptions {
|
|
15
|
+
locale?: string;
|
|
16
|
+
/** Where `asset()` resolves; the workspace library's CDN base for a document that leaves the machine. */
|
|
17
|
+
assetBaseUrl?: string;
|
|
18
|
+
brand?: BrandContext;
|
|
19
|
+
/** Loads and draws pictures and codes; without one, only PNG and JPEG data URLs are placed. */
|
|
20
|
+
images?: OfficeImageHost;
|
|
21
|
+
/** For snapshots: the source of the engine's placeholder nonce, so repeated runs fill alike. */
|
|
22
|
+
random?: () => number;
|
|
23
|
+
}
|
|
24
|
+
/** Fills a Word or PowerPoint template with the shared engine, as the render-worker does. */
|
|
25
|
+
export declare function renderOfficeLocal(project: Project, tpl: LocalTemplate, data: unknown, options?: OfficeLocalOptions): Promise<OfficeRenderResult>;
|
|
26
|
+
/**
|
|
27
|
+
* The filled parts of a Word or PowerPoint document as readable text for snapshots: each part's XML,
|
|
28
|
+
* one element per line and indented, text kept beside its element, under a `--- <part> ---` line.
|
|
29
|
+
*/
|
|
30
|
+
export declare function officeSnapshot(filled: Uint8Array): string;
|
|
31
|
+
/** Indents XML one element per line; text and the closing tag stay on the line of their element. */
|
|
32
|
+
export declare function prettyXml(xml: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* `assetBaseUrl` is where `asset()` and relative image paths resolve: the dev server's `/files`
|
|
35
|
+
* locally, the workspace library's CDN base when the document goes to the API. Without it the
|
|
36
|
+
* references stay relative, which keeps snapshots independent of any host.
|
|
37
|
+
*/
|
|
38
|
+
export declare function renderContext(project: Project, tpl: LocalTemplate, assetBaseUrl?: string, brand?: BrandContext): RenderContext;
|
|
7
39
|
export interface LocalRenderOptions {
|
|
8
40
|
mode: 'preview' | 'print';
|
|
9
41
|
locale?: string;
|
|
10
42
|
vendor?: AssembleVendor;
|
|
43
|
+
/** Where `asset()` and relative image paths resolve (see `renderContext`). */
|
|
44
|
+
assetBaseUrl?: string;
|
|
45
|
+
/** The template's `brand`; `.formfeed/brand.json` (`readBrand`) when left out. */
|
|
46
|
+
brand?: BrandContext;
|
|
11
47
|
}
|
|
12
48
|
/** Assembles the complete document with the shared engine; no browser involved. */
|
|
13
49
|
export declare function renderLocal(project: Project, tpl: LocalTemplate, data: unknown, options: LocalRenderOptions): Promise<RenderedDocument>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type EngineId } from '@formfeed/engine';
|
|
2
|
+
import type { Project } from './project-config.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* The partials a template includes, read from the project's `partials/` folder. They travel with
|
|
5
|
+
* the version (`formfeed templates push`), so a published template resolves `{% include %}` in the
|
|
6
|
+
* API and the editor, not only in the CLI.
|
|
7
|
+
*
|
|
8
|
+
* Includes nest, so every partial is analysed in turn; a name that has no file is reported instead
|
|
9
|
+
* of failing, and `validate` and `push` show it.
|
|
10
|
+
*/
|
|
11
|
+
export interface CollectedPartials {
|
|
12
|
+
/** name → source, the shape the API stores. */
|
|
13
|
+
partials: Record<string, string>;
|
|
14
|
+
/** Names no file in the partials folder matches. */
|
|
15
|
+
missing: string[];
|
|
16
|
+
/** Normalised names of included shared partials of the organisation (from the project state). */
|
|
17
|
+
shared: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare function collectPartials(project: Project, engine: EngineId, sources: Array<string | undefined>): CollectedPartials;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type EngineId } from '@formfeed/engine';
|
|
2
|
+
import type { Project } from './project-config.js';
|
|
3
|
+
/**
|
|
4
|
+
* The partials a template includes, read from the project's `partials/` folder. They travel with
|
|
5
|
+
* the version (`formfeed templates push`), so a published template resolves `{% include %}` in the
|
|
6
|
+
* API and the editor, not only in the CLI.
|
|
7
|
+
*
|
|
8
|
+
* Includes nest, so every partial is analysed in turn; a name that has no file is reported instead
|
|
9
|
+
* of failing, and `validate` and `push` show it.
|
|
10
|
+
*/
|
|
11
|
+
export interface CollectedPartials {
|
|
12
|
+
/** name → source, the shape the API stores. */
|
|
13
|
+
partials: Record<string, string>;
|
|
14
|
+
/** Names no file in the partials folder matches. */
|
|
15
|
+
missing: string[];
|
|
16
|
+
/** Normalised names of included shared partials of the organisation (from the project state). */
|
|
17
|
+
shared: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare function collectPartials(project: Project, engine: EngineId, sources: Array<string | undefined>): CollectedPartials;
|
|
@@ -5,8 +5,23 @@ export interface ProjectConfig {
|
|
|
5
5
|
region?: 'eu' | 'us';
|
|
6
6
|
templatesDir: string;
|
|
7
7
|
partialsDir: string;
|
|
8
|
+
/** The local copy of the workspace file library (`formfeed files push|pull`). */
|
|
9
|
+
filesDir: string;
|
|
8
10
|
engine: EngineId;
|
|
9
11
|
ignore: string[];
|
|
12
|
+
/** Defaults of `formfeed types` (spec 19 §2.1). */
|
|
13
|
+
types?: {
|
|
14
|
+
lang?: 'ts' | 'python';
|
|
15
|
+
/** Relative to the project root; `formfeed.d.ts` or `formfeed_templates.py` when left out. */
|
|
16
|
+
out?: string;
|
|
17
|
+
/** The module the TypeScript file augments; `@formfeed/sdk`. */
|
|
18
|
+
sdkModule?: string;
|
|
19
|
+
};
|
|
20
|
+
/** Defaults of `formfeed renders pull` (spec 20 §3.3). */
|
|
21
|
+
pull?: {
|
|
22
|
+
/** Data paths redacted on every pull (`customer.*`, `items[].name`); `--redact` paths replace them, `--no-redact` skips them. */
|
|
23
|
+
redact?: string[];
|
|
24
|
+
};
|
|
10
25
|
}
|
|
11
26
|
export interface Project {
|
|
12
27
|
root: string;
|
|
@@ -15,6 +30,7 @@ export interface Project {
|
|
|
15
30
|
config: ProjectConfig;
|
|
16
31
|
templatesDir: string;
|
|
17
32
|
partialsDir: string;
|
|
33
|
+
filesDir: string;
|
|
18
34
|
}
|
|
19
35
|
export declare const defaultProjectConfig: ProjectConfig;
|
|
20
36
|
/** Walks up from `cwd` to the nearest `formfeed.json`. */
|
|
@@ -5,8 +5,23 @@ export interface ProjectConfig {
|
|
|
5
5
|
region?: 'eu' | 'us';
|
|
6
6
|
templatesDir: string;
|
|
7
7
|
partialsDir: string;
|
|
8
|
+
/** The local copy of the workspace file library (`formfeed files push|pull`). */
|
|
9
|
+
filesDir: string;
|
|
8
10
|
engine: EngineId;
|
|
9
11
|
ignore: string[];
|
|
12
|
+
/** Defaults of `formfeed types` (spec 19 §2.1). */
|
|
13
|
+
types?: {
|
|
14
|
+
lang?: 'ts' | 'python';
|
|
15
|
+
/** Relative to the project root; `formfeed.d.ts` or `formfeed_templates.py` when left out. */
|
|
16
|
+
out?: string;
|
|
17
|
+
/** The module the TypeScript file augments; `@formfeed/sdk`. */
|
|
18
|
+
sdkModule?: string;
|
|
19
|
+
};
|
|
20
|
+
/** Defaults of `formfeed renders pull` (spec 20 §3.3). */
|
|
21
|
+
pull?: {
|
|
22
|
+
/** Data paths redacted on every pull (`customer.*`, `items[].name`); `--redact` paths replace them, `--no-redact` skips them. */
|
|
23
|
+
redact?: string[];
|
|
24
|
+
};
|
|
10
25
|
}
|
|
11
26
|
export interface Project {
|
|
12
27
|
root: string;
|
|
@@ -15,6 +30,7 @@ export interface Project {
|
|
|
15
30
|
config: ProjectConfig;
|
|
16
31
|
templatesDir: string;
|
|
17
32
|
partialsDir: string;
|
|
33
|
+
filesDir: string;
|
|
18
34
|
}
|
|
19
35
|
export declare const defaultProjectConfig: ProjectConfig;
|
|
20
36
|
/** Walks up from `cwd` to the nearest `formfeed.json`. */
|
package/types/lib/project.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EngineId, type OfficeKind, type TemplateKind, type TemplateSettings } from '@formfeed/engine';
|
|
2
2
|
import type { TemplateVersion } from '@formfeed/sdk';
|
|
3
3
|
import type { Project } from './project-config.cjs';
|
|
4
4
|
/**
|
|
@@ -9,15 +9,29 @@ import type { Project } from './project-config.cjs';
|
|
|
9
9
|
*/
|
|
10
10
|
export interface TemplateMeta {
|
|
11
11
|
name: string;
|
|
12
|
-
kind
|
|
12
|
+
/** An HTML kind, or `docx`/`pptx` for Word and PowerPoint templates. */
|
|
13
|
+
kind: TemplateKind | OfficeKind;
|
|
13
14
|
engine: EngineId;
|
|
14
15
|
description?: string | null;
|
|
15
16
|
tags?: string[];
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The document of a Word or PowerPoint template (spec 22 §7): `template.docx` or `template.pptx`
|
|
20
|
+
* instead of `template.html`. Such a folder has no markup, style, head, header, footer or partials.
|
|
21
|
+
*/
|
|
22
|
+
export interface LocalOfficeFile {
|
|
23
|
+
format: OfficeKind;
|
|
24
|
+
path: string;
|
|
25
|
+
bytes: Uint8Array;
|
|
26
|
+
sha256: string;
|
|
27
|
+
}
|
|
17
28
|
export interface LocalTemplate {
|
|
18
29
|
slug: string;
|
|
19
30
|
dir: string;
|
|
20
31
|
meta: TemplateMeta;
|
|
32
|
+
/** The Word or PowerPoint document; `null` for HTML templates. */
|
|
33
|
+
file: LocalOfficeFile | null;
|
|
34
|
+
/** Empty for Word and PowerPoint templates. */
|
|
21
35
|
html: string;
|
|
22
36
|
css: string;
|
|
23
37
|
head: string;
|
|
@@ -27,6 +41,15 @@ export interface LocalTemplate {
|
|
|
27
41
|
dataSets: Record<string, unknown>;
|
|
28
42
|
dataSchema: Record<string, unknown> | null;
|
|
29
43
|
i18n: Record<string, Record<string, string>> | null;
|
|
44
|
+
/** Partials the template includes, read from the project's folder; they travel with the version. */
|
|
45
|
+
partials: Record<string, string>;
|
|
46
|
+
/** Included names without a file; `validate` reports them and `push` refuses them. */
|
|
47
|
+
missingPartials: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Included names that are shared partials of the organisation (recorded in the state by
|
|
50
|
+
* `formfeed partials pull|push`). They resolve live on the server, so they stay out of `partials`.
|
|
51
|
+
*/
|
|
52
|
+
sharedPartials: string[];
|
|
30
53
|
}
|
|
31
54
|
export interface TemplateState {
|
|
32
55
|
/** Checksum of the remote version the folder was pulled from or pushed as. */
|
|
@@ -35,11 +58,26 @@ export interface TemplateState {
|
|
|
35
58
|
status: string;
|
|
36
59
|
/** Hash of the local files at that moment; a different hash means local edits. */
|
|
37
60
|
contentHash: string;
|
|
61
|
+
/** Word and PowerPoint templates: the document's SHA-256, so `push` uploads it only when it changed. */
|
|
62
|
+
fileSha256?: string;
|
|
63
|
+
syncedAt: string;
|
|
64
|
+
}
|
|
65
|
+
/** A shared partial of the organisation as last pulled or pushed (spec 18 §8). */
|
|
66
|
+
export interface SharedPartialState {
|
|
67
|
+
/** The remote version; `partials push` sends it as `base_version`. */
|
|
68
|
+
version: number;
|
|
69
|
+
engine: EngineId;
|
|
70
|
+
/** Hash of the local file at that moment; a different hash means local edits. */
|
|
71
|
+
contentHash: string;
|
|
38
72
|
syncedAt: string;
|
|
39
73
|
}
|
|
40
74
|
export interface ProjectState {
|
|
41
75
|
templates: Record<string, TemplateState>;
|
|
76
|
+
/** Shared partials by name; they live in `partialsDir` as `<name>.html`. */
|
|
77
|
+
sharedPartials?: Record<string, SharedPartialState>;
|
|
42
78
|
}
|
|
79
|
+
/** The file a template folder is built around, by kind. */
|
|
80
|
+
export declare const templateFileName: (kind: TemplateKind | string) => string;
|
|
43
81
|
export declare function listTemplateSlugs(project: Project): string[];
|
|
44
82
|
export declare function templateDir(project: Project, slug: string): string;
|
|
45
83
|
export declare function readTemplate(project: Project, slug: string): LocalTemplate;
|
|
@@ -48,19 +86,43 @@ export declare function defaultData(tpl: LocalTemplate, name?: string): {
|
|
|
48
86
|
name: string;
|
|
49
87
|
data: unknown;
|
|
50
88
|
};
|
|
89
|
+
/**
|
|
90
|
+
* Writes a pulled version into the template folder. A Word or PowerPoint template needs its
|
|
91
|
+
* document as `file`; the folder then holds `template.<kind>` and none of the HTML files, so a
|
|
92
|
+
* template whose kind changed leaves nothing behind that would be read as its source.
|
|
93
|
+
*/
|
|
51
94
|
export declare function writeTemplate(project: Project, slug: string, meta: TemplateMeta, version: Pick<TemplateVersion, 'html' | 'css' | 'head' | 'settings' | 'sample_data' | 'data_schema' | 'i18n'> & {
|
|
52
95
|
data_sets?: Record<string, unknown> | null;
|
|
53
|
-
|
|
96
|
+
partials?: Record<string, string> | null;
|
|
97
|
+
}, file?: Uint8Array): string;
|
|
98
|
+
/**
|
|
99
|
+
* Writes the partials of a pulled version into the project's folder (`name` or `name.html`, the
|
|
100
|
+
* two spellings `partialResolver` reads). Returns the files whose content changed, so `pull` can
|
|
101
|
+
* say that a partial shared with another template was replaced.
|
|
102
|
+
*/
|
|
103
|
+
export declare function writePartials(project: Project, partials: Record<string, string> | null): string[];
|
|
104
|
+
/**
|
|
105
|
+
* Fields of a push request besides the document: what the API's version create takes for a Word or
|
|
106
|
+
* PowerPoint template. The document itself travels as the multipart `file`.
|
|
107
|
+
*/
|
|
108
|
+
export declare function officeVersionPayload(tpl: LocalTemplate): {
|
|
109
|
+
settings: Record<string, unknown>;
|
|
110
|
+
sample_data: Record<string, unknown>;
|
|
111
|
+
data_sets: Record<string, unknown>;
|
|
112
|
+
data_schema: Record<string, unknown> | null;
|
|
113
|
+
i18n: Record<string, Record<string, string>> | null;
|
|
114
|
+
};
|
|
54
115
|
/** Files of a push request: what the API's TemplateVersionCreate takes. */
|
|
55
116
|
export declare function versionPayload(tpl: LocalTemplate): {
|
|
56
|
-
|
|
57
|
-
css: string;
|
|
58
|
-
head: string;
|
|
117
|
+
partials?: Record<string, string> | undefined;
|
|
59
118
|
settings: Record<string, unknown>;
|
|
60
119
|
sample_data: Record<string, unknown>;
|
|
61
120
|
data_sets: Record<string, unknown>;
|
|
62
121
|
data_schema: Record<string, unknown> | null;
|
|
63
122
|
i18n: Record<string, Record<string, string>> | null;
|
|
123
|
+
html: string;
|
|
124
|
+
css: string;
|
|
125
|
+
head: string;
|
|
64
126
|
};
|
|
65
127
|
/** Stable hash of the local files; compared with the state to detect local edits. */
|
|
66
128
|
export declare function contentHash(tpl: LocalTemplate): string;
|
|
@@ -68,5 +130,19 @@ export declare function readState(project: Project): ProjectState;
|
|
|
68
130
|
export declare function writeState(project: Project, state: ProjectState): void;
|
|
69
131
|
export declare function recordSync(project: Project, slug: string, version: Pick<TemplateVersion, 'checksum' | 'number' | 'status'>, tpl: LocalTemplate): void;
|
|
70
132
|
export declare function titleFromSlug(slug: string): string;
|
|
71
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Resolves `{% include %}` / partials from the project's partials folder (`name` or `name.html`).
|
|
135
|
+
* A name that matches a shared partial of the state only after normalisation (`Letterhead.j2` for
|
|
136
|
+
* `letterhead`) falls back to that partial's file, the way the server matches shared partials.
|
|
137
|
+
*/
|
|
72
138
|
export declare function partialResolver(project: Project): (name: string) => string | undefined;
|
|
139
|
+
/** Where a shared partial lives locally: `<partialsDir>/<name>.html`. */
|
|
140
|
+
export declare function sharedPartialPath(project: Project, name: string): string;
|
|
141
|
+
/** Normalised names of the shared partials recorded for one engine; other engines' partials never resolve. */
|
|
142
|
+
export declare function sharedPartialNames(project: Project, engine: EngineId): Set<string>;
|
|
143
|
+
export declare const partialContentHash: (source: string) => string;
|
|
144
|
+
/** Records a pulled or pushed shared partial with the remote version and the hash of `source`. */
|
|
145
|
+
export declare function recordSharedPartial(project: Project, name: string, remote: {
|
|
146
|
+
version: number;
|
|
147
|
+
engine: EngineId;
|
|
148
|
+
}, source: string): void;
|