@format.dev/types 0.0.0 → 0.1.1

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 CHANGED
@@ -1,32 +1,18 @@
1
1
  # @format.dev/types
2
2
 
3
- **This is a bootstrap placeholder. It reserves the package name and does nothing else.**
3
+ Type declarations shared by the Format SDKs. These interfaces describe a compiled document renderer, the document it produces, and the asset configuration both carry. The package contains types only and adds nothing to your bundle.
4
4
 
5
- Format is not released yet. Version `0.0.0` is not a usable version of this
6
- package: it contains no implementation, and installing it gets you an empty
7
- module.
5
+ ## Exports
8
6
 
9
- ## Why it exists
7
+ - `FormatRenderer` describes a compiled document renderer: `render(data)` plus the asset configuration surface.
8
+ - `FormatDocument` is the result of `render()`. Pass it directly to `FormatClient.pdf()`.
9
+ - `FormatAssetConfig` holds the renderer-scoped asset settings: `getAssetsUrl`, `setAssetsUrl`, and `setZipOptions`.
10
+ - `ZipOptions` configures a runtime ZIP build. `@format.dev/zip` re-exports it, so both sides of the compile-and-zip flow share one shape.
10
11
 
11
- npm binds a package’s trusted publisher, and its staged-publishing flow, to a
12
- package that already exists. Creating these names ahead of the first release is
13
- what lets every real release go out through a reviewed, credential-free
14
- workflow rather than through a token somebody holds.
12
+ ## Where these types appear
15
13
 
16
- This version is published deliberately and deprecated immediately.
14
+ The SDKs re-export them: `FormatDocument` from `@format.dev/client`, the renderer types from `@format.dev/compile`, and `ZipOptions` from `@format.dev/zip`.
17
15
 
18
- ## Why a bare install resolves it
16
+ ## What belongs here
19
17
 
20
- npm creates a `latest` tag on a package’s first publish and will not remove it,
21
- so `latest` points at this placeholder until Format reaches general
22
- availability. That is why the deprecation warning is there.
23
-
24
- - Beta releases go out under the `beta` tag.
25
- - General availability is when `latest` moves to a real release.
26
-
27
- ## Format
28
-
29
- - https://format.dev
30
- - https://github.com/format-hq/format-js
31
-
32
- Licensed under MIT. The full text ships beside this file.
18
+ Types only. Nothing with runtime behavior lands in this package; shared runtime code belongs in `@format.dev/utils`. The JSDoc on these interfaces renders on public format.dev docs, so write with that audience in mind.
@@ -0,0 +1,2 @@
1
+ import { FormatAssetConfig, FormatDocument, FormatRenderer, RemoteAssetFetcher, ZipOptions } from "./renderer.js";
2
+ export { type FormatAssetConfig, type FormatDocument, type FormatRenderer, type RemoteAssetFetcher, type ZipOptions };
package/dist/index.js ADDED
File without changes
@@ -0,0 +1,118 @@
1
+ //#region src/renderer.d.ts
2
+ /** Fetches one remote asset and returns its bytes with the MIME type the server reported. */
3
+ type RemoteAssetFetcher = (params: {
4
+ url: string;
5
+ headers?: Headers | Record<string, string> | [string, string][];
6
+ timeoutMs?: number;
7
+ }) => Promise<{
8
+ bytes: Uint8Array;
9
+ mimeType?: string;
10
+ }>;
11
+ /**
12
+ * Options for the runtime zip build (dynamic asset mode). The single source of
13
+ * truth for the option shape, shared by the renderer's `setZipOptions` and
14
+ * `@format.dev/zip`'s `zip()`, which re-exports this type as `ZipOptions`.
15
+ */
16
+ interface ZipOptions {
17
+ /** Log and skip missing assets instead of rejecting on the first one. */
18
+ skipMissing?: boolean;
19
+ /** Deflate options. Only `level` (0–9) is read. */
20
+ zlib?: {
21
+ level?: number;
22
+ };
23
+ /**
24
+ * Fetch remote references when calling `zip()`. By default, remote assets are not fetched.
25
+ * Unless enabled, a remote asset path found at `zip()` will throw `RemoteAssetsDisabledError`.
26
+ *
27
+ * Generally not recommended on a production render path — fetching
28
+ * per render reintroduces the network as a failure mode and repeats on
29
+ * every render. Prefer local files.
30
+ *
31
+ * @summary Control whether `zip()` fetches remote asset references in your HTML.
32
+ */
33
+ remoteAssets?: {
34
+ enabled?: boolean;
35
+ headers?: Headers | Record<string, string> | [string, string][];
36
+ timeoutMs?: number;
37
+ /**
38
+ * Replaces the built-in network fetch for remote references. It is called
39
+ * once per URL, with the headers and timeout from these options. Supply a
40
+ * caching implementation when the same document is zipped repeatedly, so
41
+ * each URL is downloaded once rather than once per build.
42
+ */
43
+ fetch?: RemoteAssetFetcher;
44
+ };
45
+ }
46
+ /**
47
+ * Asset configuration for a renderer. These settings are renderer-scoped: they
48
+ * apply to every document the renderer produces. Set them once before rendering
49
+ * rather than on a render result.
50
+ */
51
+ interface FormatAssetConfig {
52
+ /**
53
+ * Returns the URL the renderer will use to locate the assets ZIP.
54
+ * On the `node` target this is auto-initialized to the local `assets.zip`.
55
+ * On `browser` and `worker` targets it returns `undefined` until `setAssetsUrl` is called.
56
+ *
57
+ * @summary Returns the URL the renderer will use to locate the assets ZIP.
58
+ */
59
+ getAssetsUrl(): string | undefined;
60
+ /**
61
+ * Sets the assets URL at runtime. Call this before `render()` when your assets ZIP is
62
+ * hosted on a CDN or object storage bucket.
63
+ *
64
+ * @summary Sets the assets URL at runtime.
65
+ */
66
+ setAssetsUrl(url: string): void;
67
+ /**
68
+ * Sets options for a runtime ZIP build (dynamic asset mode). Call this
69
+ * before `render()`, e.g. to enable `remoteAssets` for documents that
70
+ * reference remote URLs. Has no effect if your ZIP was built at compile.
71
+ *
72
+ * @summary set `ZipOptions` at runtime.
73
+ */
74
+ setZipOptions?(options: ZipOptions | undefined): void;
75
+ }
76
+ /**
77
+ * The result of calling `renderer.render()`. Pass this directly to `FormatClient.pdf()`.
78
+ */
79
+ interface FormatDocument {
80
+ /** The rendered Format-compatible template string. */
81
+ html: string;
82
+ /**
83
+ * Returns a web stream to the assets ZIP.
84
+ *
85
+ * If the assets ZIP was built at compile, bytes will be loaded from the filesystem.
86
+ * If using a runtime outside of Node, bytes will be loaded via `fetch` using the URL
87
+ * set with `setAssetsUrl()`. Otherwise, returns undefined.
88
+ *
89
+ * @summary Get a web stream of the assets `ZIP` attached to the renderer.
90
+ */
91
+ getAssetsWebStream(): Promise<ReadableStream<Uint8Array> | undefined>;
92
+ }
93
+ /**
94
+ * A compiled Format document renderer. Configure assets once, then call
95
+ * `render()` with your data to produce a `FormatDocument` that can be passed
96
+ * directly to `FormatClient.pdf()`.
97
+ */
98
+ interface FormatRenderer extends FormatAssetConfig {
99
+ /**
100
+ * Renders the document with the provided data and returns a `FormatDocument`.
101
+ *
102
+ * @param data - A JavaScript object passed to your document template with any arbitrary data.
103
+ */
104
+ render(data?: Record<string, unknown>): Promise<FormatDocument>;
105
+ /**
106
+ * Returns a web stream to the assets ZIP.
107
+ *
108
+ * If the assets ZIP was built at compile, bytes will be loaded from the filesystem.
109
+ * If using a runtime outside of Node, bytes will be loaded via `fetch` using the URL
110
+ * set with `setAssetsUrl()`. Otherwise, returns undefined.
111
+ *
112
+ * @summary Get a web stream of the assets `ZIP` attached to the renderer.
113
+ */
114
+ getAssetsWebStream(): Promise<ReadableStream<Uint8Array> | undefined>;
115
+ }
116
+ //#endregion
117
+ export { FormatAssetConfig, FormatDocument, FormatRenderer, RemoteAssetFetcher, ZipOptions };
118
+ //# sourceMappingURL=renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.d.ts","names":[],"sources":["../src/renderer.ts"],"sourcesContent":[],"mappings":";;AACY,KAAA,kBAAA,GAAkB,CAAA,MAAA,EAAA;EAEnB,GAAA,EAAA,MAAA;EAAU,OAAA,CAAA,EAAV,OAAU,GAAA,MAAA,CAAA,MAAA,EAAA,MAAA,CAAA,GAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA;EAEE,SAAA,CAAA,EAAA,MAAA;CAAjB,EAAA,GAAA,OAAA,CAAA;EAAO,KAAA,EAAU,UAAV;EAOI,QAAA,CAAA,EAAA,MAAU;CAmBf,CAAA;;;;AAkBZ;AA+BA;AAa8C,UAjF7B,UAAA,CAiF6B;EAAf;EAAR,WAAA,CAAA,EAAA,OAAA;EAAO;EAQb,IAAA,CAAA,EAAA;IAMF,KAAA,CAAA,EAAA,MAAA;EAAkC,CAAA;EAAR;;;;;;;;;;;;cA5E7B,UAAU;;;;;;;;YASZ;;;;;;;;UASO,iBAAA;;;;;;;;;;;;;;;;;;;;;;;0BAyBQ;;;;;UAMR,cAAA;;;;;;;;;;;;wBAaM,QAAQ,eAAe;;;;;;;UAQ7B,cAAA,SAAuB;;;;;;gBAMzB,0BAA0B,QAAQ;;;;;;;;;;wBAW1B,QAAQ,eAAe"}
File without changes
package/package.json CHANGED
@@ -1,32 +1,38 @@
1
1
  {
2
- "name": "@format.dev/types",
3
- "version": "0.0.0",
4
- "description": "A bootstrap placeholder reserving this package name. Format is not released yet.",
5
- "license": "MIT",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/format-hq/format-js.git",
9
- "directory": "packages/types"
10
- },
11
- "homepage": "https://format.dev",
12
- "files": [
13
- "LICENSE",
14
- "README.md",
15
- "index.d.ts",
16
- "index.js"
17
- ],
18
- "type": "module",
19
- "main": "./index.js",
20
- "types": "./index.d.ts",
21
- "exports": {
22
- ".": {
23
- "types": "./index.d.ts",
24
- "default": "./index.js"
25
- }
26
- },
27
- "publishConfig": {
28
- "access": "public",
29
- "tag": "bootstrap",
30
- "registry": "https://registry.npmjs.org/"
31
- }
32
- }
2
+ "name": "@format.dev/types",
3
+ "version": "0.1.1",
4
+ "license": "MIT",
5
+ "description": "Shared type declarations for the Format SDKs.",
6
+ "author": "the format.dev developers",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/format-hq/format-js.git",
10
+ "directory": "packages/types"
11
+ },
12
+ "type": "module",
13
+ "sideEffects": false,
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "LICENSE"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "devDependencies": {
28
+ "rimraf": "^6.1.2",
29
+ "tsdown": "0.17.0-beta.6",
30
+ "typescript": "^5"
31
+ },
32
+ "scripts": {
33
+ "clean": "rimraf dist",
34
+ "build": "tsdown",
35
+ "dev": "tsdown --watch",
36
+ "typecheck": "tsc -p tsconfig.json --noEmit"
37
+ }
38
+ }
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- // This is a bootstrap placeholder. Format is not released yet.
2
- export {}
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- // This is a bootstrap placeholder. Format is not released yet, and this version
2
- // carries no implementation. See README.md.
3
- export {}