embedoc 0.9.0 → 0.9.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
@@ -872,6 +872,8 @@ npm test
872
872
 
873
873
  ## API Reference
874
874
 
875
+ > 📖 **See [docs/api/README.md](./docs/api/README.md) for detailed Embed API documentation.**
876
+
875
877
  ### Exported Functions
876
878
 
877
879
  ```typescript
@@ -0,0 +1,49 @@
1
+ /**
2
+ * embedoc Embed API
3
+ *
4
+ * This module exports all types and functions needed for writing custom embeds.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { defineEmbed, type EmbedContext, type EmbedResult } from 'embedoc';
9
+ *
10
+ * export default defineEmbed({
11
+ * dependsOn: ['my_datasource'],
12
+ * async render(ctx: EmbedContext): Promise<EmbedResult> {
13
+ * const data = await ctx.datasources.my_datasource.query('SELECT * FROM table');
14
+ * return { content: ctx.markdown.table(['Column'], data.map(r => [r.name])) };
15
+ * }
16
+ * });
17
+ * ```
18
+ *
19
+ * @packageDocumentation
20
+ */
21
+ export type {
22
+ /**
23
+ * Embed definition interface.
24
+ * Use with {@link defineEmbed} to create custom embeds.
25
+ */
26
+ EmbedDefinition,
27
+ /**
28
+ * Context object passed to the embed's render function.
29
+ * Provides access to parameters, datasources, and helpers.
30
+ */
31
+ EmbedContext,
32
+ /**
33
+ * Result returned from an embed's render function.
34
+ */
35
+ EmbedResult,
36
+ /**
37
+ * Helper interface for generating Markdown content.
38
+ */
39
+ MarkdownHelper,
40
+ /**
41
+ * Datasource interface for querying data.
42
+ */
43
+ Datasource,
44
+ /**
45
+ * Query result type (array of records).
46
+ */
47
+ QueryResult, } from './types/index.js';
48
+ export { defineEmbed } from './index.js';
49
+ //# sourceMappingURL=embed-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embed-api.d.ts","sourceRoot":"","sources":["../src/embed-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,YAAY;AACV;;;GAGG;AACH,eAAe;AAEf;;;GAGG;AACH,YAAY;AAEZ;;GAEG;AACH,WAAW;AAEX;;GAEG;AACH,cAAc;AAEd;;GAEG;AACH,UAAU;AAEV;;GAEG;AACH,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * embedoc Embed API
3
+ *
4
+ * This module exports all types and functions needed for writing custom embeds.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { defineEmbed, type EmbedContext, type EmbedResult } from 'embedoc';
9
+ *
10
+ * export default defineEmbed({
11
+ * dependsOn: ['my_datasource'],
12
+ * async render(ctx: EmbedContext): Promise<EmbedResult> {
13
+ * const data = await ctx.datasources.my_datasource.query('SELECT * FROM table');
14
+ * return { content: ctx.markdown.table(['Column'], data.map(r => [r.name])) };
15
+ * }
16
+ * });
17
+ * ```
18
+ *
19
+ * @packageDocumentation
20
+ */
21
+ // Re-export defineEmbed function
22
+ export { defineEmbed } from './index.js';
23
+ //# sourceMappingURL=embed-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embed-api.js","sourceRoot":"","sources":["../src/embed-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAqCH,iCAAiC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.d.ts CHANGED
@@ -26,9 +26,15 @@ export { createDatasource, initializeDatasources, closeDatasources, SqliteDataso
26
26
  export { createMarkdownHelper } from './helpers/markdown.js';
27
27
  import type { DefineEmbedFn } from './types/index.js';
28
28
  /**
29
- * Helper function to define an embed
29
+ * Define a custom embed for generating content in documents.
30
30
  *
31
- * @example
31
+ * Embeds are TypeScript modules that generate content for markers
32
+ * in your documents. Use this function to create type-safe embed definitions.
33
+ *
34
+ * @param definition - The embed definition object
35
+ * @returns The same definition object (for type inference)
36
+ *
37
+ * @example Basic embed
32
38
  * ```typescript
33
39
  * import { defineEmbed } from 'embedoc';
34
40
  *
@@ -36,7 +42,7 @@ import type { DefineEmbedFn } from './types/index.js';
36
42
  * dependsOn: ['metadata_db'],
37
43
  * async render(ctx) {
38
44
  * const { id } = ctx.params;
39
- * const data = await ctx.datasources.metadata_db.query(
45
+ * const data = await ctx.datasources['metadata_db'].query(
40
46
  * 'SELECT * FROM tables WHERE name = ?',
41
47
  * [id]
42
48
  * );
@@ -44,7 +50,54 @@ import type { DefineEmbedFn } from './types/index.js';
44
50
  * }
45
51
  * });
46
52
  * ```
53
+ *
54
+ * @example Embed with multiple datasources
55
+ * ```typescript
56
+ * import { defineEmbed } from 'embedoc';
57
+ *
58
+ * export default defineEmbed({
59
+ * dependsOn: ['users_db', 'config'],
60
+ * async render(ctx) {
61
+ * const users = await ctx.datasources['users_db'].getAll();
62
+ * const config = await ctx.datasources['config'].getAll();
63
+ *
64
+ * return {
65
+ * content: ctx.markdown.table(
66
+ * ['Name', 'Role'],
67
+ * users.map(u => [u.name, u.role])
68
+ * )
69
+ * };
70
+ * }
71
+ * });
72
+ * ```
73
+ *
74
+ * @example Embed using frontmatter and parameters
75
+ * ```typescript
76
+ * import { defineEmbed } from 'embedoc';
77
+ *
78
+ * export default defineEmbed({
79
+ * async render(ctx) {
80
+ * // Access marker parameters: <!--@embedoc:my_embed title="Hello"-->
81
+ * const { title } = ctx.params;
82
+ *
83
+ * // Access document frontmatter
84
+ * const author = ctx.frontmatter['author'] as string;
85
+ *
86
+ * return {
87
+ * content: ctx.markdown.heading(title, 2) + '\n\nBy ' + author
88
+ * };
89
+ * }
90
+ * });
91
+ * ```
92
+ *
93
+ * @see {@link EmbedDefinition} for the definition interface
94
+ * @see {@link EmbedContext} for the context object passed to render
95
+ * @see {@link MarkdownHelper} for markdown generation utilities
47
96
  */
48
97
  export declare const defineEmbed: DefineEmbedFn;
98
+ /**
99
+ * Alias for {@link defineEmbed}.
100
+ * @deprecated Use `defineEmbed` instead for consistency.
101
+ */
49
102
  export declare const defineTemplate: DefineEmbedFn;
50
103
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,YAAY,EAEV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,sBAAsB,EAEtB,YAAY,EACZ,eAAe,EAEf,WAAW,EACX,UAAU,EACV,iBAAiB,EAEjB,cAAc,EACd,YAAY,EACZ,WAAW,EACX,eAAe,EACf,aAAa,EAEb,iBAAiB,EAEjB,aAAa,EACb,cAAc,EACd,WAAW,EACX,UAAU,GACX,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,cAAc,EACd,UAAU,EACV,WAAW,EACX,kBAAkB,GACnB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3E,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,cAAc,EACd,cAAc,GACf,MAAM,wBAAwB,CAAC;AAGhC,OA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AAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,cAAc,EACd,cAAc,GACf,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,eAAO,MAAM,WAAW,EAAE,aAA2D,CAAC;AAEtF;;;GAGG;AACH,eAAO,MAAM,cAAc,eAAc,CAAC"}
package/dist/index.js CHANGED
@@ -26,9 +26,15 @@ export { createDatasource, initializeDatasources, closeDatasources, SqliteDataso
26
26
  // Helpers
27
27
  export { createMarkdownHelper } from './helpers/markdown.js';
28
28
  /**
29
- * Helper function to define an embed
29
+ * Define a custom embed for generating content in documents.
30
30
  *
31
- * @example
31
+ * Embeds are TypeScript modules that generate content for markers
32
+ * in your documents. Use this function to create type-safe embed definitions.
33
+ *
34
+ * @param definition - The embed definition object
35
+ * @returns The same definition object (for type inference)
36
+ *
37
+ * @example Basic embed
32
38
  * ```typescript
33
39
  * import { defineEmbed } from 'embedoc';
34
40
  *
@@ -36,7 +42,7 @@ export { createMarkdownHelper } from './helpers/markdown.js';
36
42
  * dependsOn: ['metadata_db'],
37
43
  * async render(ctx) {
38
44
  * const { id } = ctx.params;
39
- * const data = await ctx.datasources.metadata_db.query(
45
+ * const data = await ctx.datasources['metadata_db'].query(
40
46
  * 'SELECT * FROM tables WHERE name = ?',
41
47
  * [id]
42
48
  * );
@@ -44,8 +50,54 @@ export { createMarkdownHelper } from './helpers/markdown.js';
44
50
  * }
45
51
  * });
46
52
  * ```
53
+ *
54
+ * @example Embed with multiple datasources
55
+ * ```typescript
56
+ * import { defineEmbed } from 'embedoc';
57
+ *
58
+ * export default defineEmbed({
59
+ * dependsOn: ['users_db', 'config'],
60
+ * async render(ctx) {
61
+ * const users = await ctx.datasources['users_db'].getAll();
62
+ * const config = await ctx.datasources['config'].getAll();
63
+ *
64
+ * return {
65
+ * content: ctx.markdown.table(
66
+ * ['Name', 'Role'],
67
+ * users.map(u => [u.name, u.role])
68
+ * )
69
+ * };
70
+ * }
71
+ * });
72
+ * ```
73
+ *
74
+ * @example Embed using frontmatter and parameters
75
+ * ```typescript
76
+ * import { defineEmbed } from 'embedoc';
77
+ *
78
+ * export default defineEmbed({
79
+ * async render(ctx) {
80
+ * // Access marker parameters: <!--@embedoc:my_embed title="Hello"-->
81
+ * const { title } = ctx.params;
82
+ *
83
+ * // Access document frontmatter
84
+ * const author = ctx.frontmatter['author'] as string;
85
+ *
86
+ * return {
87
+ * content: ctx.markdown.heading(title, 2) + '\n\nBy ' + author
88
+ * };
89
+ * }
90
+ * });
91
+ * ```
92
+ *
93
+ * @see {@link EmbedDefinition} for the definition interface
94
+ * @see {@link EmbedContext} for the context object passed to render
95
+ * @see {@link MarkdownHelper} for markdown generation utilities
47
96
  */
48
97
  export const defineEmbed = (definition) => definition;
49
- // Export alias for documentation consistency
98
+ /**
99
+ * Alias for {@link defineEmbed}.
100
+ * @deprecated Use `defineEmbed` instead for consistency.
101
+ */
50
102
  export const defineTemplate = defineEmbed;
51
103
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAmCH,iBAAiB;AACjB,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,kBAAk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