@voxgig/sdkgen 4.36.0 → 4.37.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/bin/voxgig-sdkgen +1 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/go/Entity_go.ts +1 -1
- package/project/.sdk/src/cmp/go/MainEntity_go.ts +1 -1
- package/project/.sdk/src/cmp/go/Main_go.ts +7 -3
- package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +3 -3
- package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +1 -1
- package/project/.sdk/src/cmp/go-cli/fragment/words.fragment.go +1 -1
- package/project/.sdk/src/cmp/go-mcp/fragment/tools.fragment.go +1 -1
- package/project/.sdk/src/cmp/rust/EntityOperation_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/Main_rust.ts +3 -1
- package/project/.sdk/src/cmp/rust/ReadmeHowto_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeModel_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeQuick_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeRef_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeTopQuick_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/ReadmeTopTest_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +1 -1
- package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +2 -2
- package/project/.sdk/tm/c/core/sdk.h +2 -2
- package/project/.sdk/tm/go/core/helpers.go +1 -1
- package/project/.sdk/tm/go/core/types.go +9 -1
- package/project/.sdk/tm/rust/core/helpers.rs +1 -1
- package/project/.sdk/tm/rust/core/types.rs +2 -2
- package/project/sdkgen-package.json +1 -1
package/bin/voxgig-sdkgen
CHANGED
package/package.json
CHANGED
|
@@ -44,7 +44,7 @@ const Entity = cmp(function Entity(props: any) {
|
|
|
44
44
|
|
|
45
45
|
// For each CRUD op: if the spec defines it, splice in the real
|
|
46
46
|
// implementation. Otherwise emit a stub that satisfies the static
|
|
47
|
-
//
|
|
47
|
+
// ProjectNameEntityBase interface (so the package compiles) but errors
|
|
48
48
|
// at runtime if the caller invokes an unsupported op.
|
|
49
49
|
const opfrags =
|
|
50
50
|
(['load', 'list', 'create', 'update', 'patch', 'remove']
|
|
@@ -14,7 +14,7 @@ const MainEntity = cmp(async function MainEntity(props: any) {
|
|
|
14
14
|
// ${entity.Name} returns a ${entity.Name} entity bound to this client.
|
|
15
15
|
// Idiomatic usage: client.${entity.Name}(nil).List(nil, nil) or
|
|
16
16
|
// client.${entity.Name}(nil).Load(map[string]any{"id": ...}, nil).
|
|
17
|
-
func (sdk *${model.const.Name}SDK) ${entity.Name}(data map[string]any) ${model.const.Name}
|
|
17
|
+
func (sdk *${model.const.Name}SDK) ${entity.Name}(data map[string]any) ${model.const.Name}EntityBase {
|
|
18
18
|
return New${entity.Name}EntityFunc(sdk, data)
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -129,7 +129,7 @@ var NewBaseFeatureFunc func() Feature
|
|
|
129
129
|
})
|
|
130
130
|
|
|
131
131
|
each(entity, (ent: any) => {
|
|
132
|
-
Content(`var New${ent.Name}EntityFunc func(client *${model.const.Name}SDK, entopts map[string]any) ${model.const.Name}
|
|
132
|
+
Content(`var New${ent.Name}EntityFunc func(client *${model.const.Name}SDK, entopts map[string]any) ${model.const.Name}EntityBase
|
|
133
133
|
|
|
134
134
|
`)
|
|
135
135
|
})
|
|
@@ -153,7 +153,11 @@ type Context = core.Context
|
|
|
153
153
|
type Utility = core.Utility
|
|
154
154
|
type Feature = core.Feature
|
|
155
155
|
type Entity = core.Entity
|
|
156
|
-
type ${model.const.Name}
|
|
156
|
+
type ${model.const.Name}EntityBase = core.${model.const.Name}EntityBase
|
|
157
|
+
|
|
158
|
+
// Deprecated: use ${model.const.Name}EntityBase.
|
|
159
|
+
type ${model.const.Name}Entity = core.${model.const.Name}EntityBase
|
|
160
|
+
|
|
157
161
|
type StreamItem = core.StreamItem
|
|
158
162
|
type FetcherFunc = core.FetcherFunc
|
|
159
163
|
type Spec = core.Spec
|
|
@@ -185,7 +189,7 @@ func init() {
|
|
|
185
189
|
})
|
|
186
190
|
|
|
187
191
|
each(entity, (ent: any) => {
|
|
188
|
-
Content(` core.New${ent.Name}EntityFunc = func(client *core.${model.const.Name}SDK, entopts map[string]any) core.${model.const.Name}
|
|
192
|
+
Content(` core.New${ent.Name}EntityFunc = func(client *core.${model.const.Name}SDK, entopts map[string]any) core.${model.const.Name}EntityBase {
|
|
189
193
|
return entity.${entityConstructorName(ent, entityCollection(model))}(client, entopts)
|
|
190
194
|
}
|
|
191
195
|
`)
|
|
@@ -121,14 +121,14 @@ Creates a test-mode client with mock transport. Both arguments may be \`nil\`.
|
|
|
121
121
|
|
|
122
122
|
each(entityList, (ent: any) => {
|
|
123
123
|
const article = /^[aeiou]/i.test(ent.Name) ? 'an' : 'a'
|
|
124
|
-
Content(`| \`${ent.Name}\` | \`(data map[string]any) ${model.const.Name}
|
|
124
|
+
Content(`| \`${ent.Name}\` | \`(data map[string]any) ${model.const.Name}EntityBase\` | Create ${article} ${ent.Name} entity instance. |
|
|
125
125
|
`)
|
|
126
126
|
})
|
|
127
127
|
|
|
128
128
|
Content(`
|
|
129
|
-
### Entity interface (${model.const.Name}
|
|
129
|
+
### Entity interface (${model.const.Name}EntityBase)
|
|
130
130
|
|
|
131
|
-
All entities implement the \`${model.const.Name}
|
|
131
|
+
All entities implement the \`${model.const.Name}EntityBase\` interface.
|
|
132
132
|
|
|
133
133
|
| Method | Signature | Description |
|
|
134
134
|
| --- | --- | --- |
|
|
@@ -119,7 +119,7 @@ client := sdk.TestSDK(testopts, sdkopts)
|
|
|
119
119
|
|
|
120
120
|
|
|
121
121
|
publishedEntities.map((ent: any) => {
|
|
122
|
-
Content(`#### \`${ent.Name}(data map[string]any) ${model.const.Name}
|
|
122
|
+
Content(`#### \`${ent.Name}(data map[string]any) ${model.const.Name}EntityBase\`
|
|
123
123
|
|
|
124
124
|
Create a new \`${ent.Name}\` entity instance. Pass \`nil\` for no initial data.
|
|
125
125
|
|
|
@@ -75,7 +75,7 @@ func runOp(client *sdk.ProjectNameSDK, op string, query *eng.Value, entityAtom e
|
|
|
75
75
|
|
|
76
76
|
// entityFor dispatches on the lowercase entity name. The generator
|
|
77
77
|
// emits one `case "<name>":` per entity defined in the SDK model.
|
|
78
|
-
func entityFor(client *sdk.ProjectNameSDK, name string) (sdk.
|
|
78
|
+
func entityFor(client *sdk.ProjectNameSDK, name string) (sdk.ProjectNameEntityBase, error) {
|
|
79
79
|
switch strings.ToLower(name) {
|
|
80
80
|
// <[SLOT:entityCases]>
|
|
81
81
|
}
|
|
@@ -76,7 +76,7 @@ func runOp(_ context.Context, client *sdk.ProjectNameSDK, op string, entity stri
|
|
|
76
76
|
|
|
77
77
|
// entityFor dispatches on the lowercase entity name. The generator
|
|
78
78
|
// emits one `case "<name>":` per entity defined in the SDK model.
|
|
79
|
-
func entityFor(client *sdk.ProjectNameSDK, name string) (sdk.
|
|
79
|
+
func entityFor(client *sdk.ProjectNameSDK, name string) (sdk.ProjectNameEntityBase, error) {
|
|
80
80
|
switch strings.ToLower(name) {
|
|
81
81
|
// <[SLOT:entityCases]>
|
|
82
82
|
}
|
|
@@ -9,7 +9,7 @@ const EntityOperation = cmp(function Operation(props: any) {
|
|
|
9
9
|
const { model } = props.ctx$
|
|
10
10
|
const { ff, opname, entity, entrep, cls } = props
|
|
11
11
|
|
|
12
|
-
// The op marker sits inside `impl
|
|
12
|
+
// The op marker sits inside `impl ProjectNameEntityBase for EntyClass`
|
|
13
13
|
// indented one level; indent the whole spliced method by the marker's
|
|
14
14
|
// own leading whitespace so the emitted rust nests correctly.
|
|
15
15
|
let { indent } = props
|
|
@@ -207,8 +207,10 @@ pub use crate::core::result::{SdkResult, StreamFn};
|
|
|
207
207
|
pub use crate::core::sdk::{test_sdk, ${model.const.Name}SDK};
|
|
208
208
|
pub use crate::core::spec::Spec;
|
|
209
209
|
pub use crate::core::types::{
|
|
210
|
-
Entity, Feature, FeatureRef, FetcherFn, OutVal, ${model.const.Name}
|
|
210
|
+
Entity, Feature, FeatureRef, FetcherFn, OutVal, ${model.const.Name}EntityBase,
|
|
211
211
|
};
|
|
212
|
+
// The trait's former name, kept so code written against it still compiles.
|
|
213
|
+
pub use crate::core::types::${model.const.Name}EntityBase as ${model.const.Name}Entity;
|
|
212
214
|
pub use crate::core::utility_type::Utility;
|
|
213
215
|
pub use crate::feature::base::BaseFeature;
|
|
214
216
|
pub use crate::utility::jsonparse::json_parse;
|
|
@@ -116,7 +116,7 @@ println!("{:?}", getp(&fetchdef, "headers"));
|
|
|
116
116
|
Create a mock client for unit testing — no server required:
|
|
117
117
|
|
|
118
118
|
\`\`\`rust
|
|
119
|
-
use ${rustcrate}::{jo, test_sdk, ${model.const.Name}
|
|
119
|
+
use ${rustcrate}::{jo, test_sdk, ${model.const.Name}EntityBase, Entity, Value};
|
|
120
120
|
|
|
121
121
|
let client = test_sdk(Value::Noval, Value::Noval);
|
|
122
122
|
|
|
@@ -100,7 +100,7 @@ ${opRows}
|
|
|
100
100
|
Entity operations return the entity on \`Ok\`, and \`list\` a \`Vec\` of
|
|
101
101
|
entities, one per record; \`data(None)\` reads an entity's record. \`Err\` is
|
|
102
102
|
the branded error. The operations are methods of the
|
|
103
|
-
\`${model.const.Name}
|
|
103
|
+
\`${model.const.Name}EntityBase\` trait and \`data\` of the \`Entity\` trait, so
|
|
104
104
|
import both.
|
|
105
105
|
|
|
106
106
|
The \`direct()\` escape hatch resolves to \`Ok\` even on a non-2xx response —
|
|
@@ -48,7 +48,7 @@ const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
|
|
|
48
48
|
Content(`### 1. Create a client
|
|
49
49
|
|
|
50
50
|
\`\`\`rust
|
|
51
|
-
use ${rustcrate}::{getp, jo, ${model.const.Name}
|
|
51
|
+
use ${rustcrate}::{getp, jo, ${model.const.Name}EntityBase, ${model.const.Name}SDK, Entity, Value};
|
|
52
52
|
|
|
53
53
|
let client = ${ctor};
|
|
54
54
|
\`\`\`
|
|
@@ -77,7 +77,7 @@ Complete API reference for the ${model.Name} ${target.title} SDK.
|
|
|
77
77
|
`)
|
|
78
78
|
|
|
79
79
|
Content(`\`\`\`rust
|
|
80
|
-
use ${rustcrate}::{jo, ${model.const.Name}
|
|
80
|
+
use ${rustcrate}::{jo, ${model.const.Name}EntityBase, ${model.const.Name}SDK, Entity, Value};
|
|
81
81
|
|
|
82
82
|
let client = ${model.const.Name}SDK::new(options);
|
|
83
83
|
\`\`\`
|
|
@@ -38,7 +38,7 @@ const ReadmeTopQuick = cmp(function ReadmeTopQuick(props: any) {
|
|
|
38
38
|
: `${model.const.Name}SDK::new(Value::Noval)`
|
|
39
39
|
|
|
40
40
|
Content(`\`\`\`rust
|
|
41
|
-
use ${rustcrate}::{jo, ${model.const.Name}
|
|
41
|
+
use ${rustcrate}::{jo, ${model.const.Name}EntityBase, ${model.const.Name}SDK, Entity, Value};
|
|
42
42
|
|
|
43
43
|
let client = ${ctor};
|
|
44
44
|
|
|
@@ -34,7 +34,7 @@ const ReadmeTopTest = cmp(function ReadmeTopTest(props: any) {
|
|
|
34
34
|
const { entity: exampleEntity, primaryOp } = pickExampleEntity(entity)
|
|
35
35
|
|
|
36
36
|
Content(`\`\`\`rust
|
|
37
|
-
use ${rustcrate}::{jo, test_sdk, ${model.const.Name}
|
|
37
|
+
use ${rustcrate}::{jo, test_sdk, ${model.const.Name}EntityBase, Entity, Value};
|
|
38
38
|
|
|
39
39
|
let client = test_sdk(Value::Noval, Value::Noval);
|
|
40
40
|
`)
|
|
@@ -135,7 +135,7 @@ use ${rustcrate}::core::types::OutVal;
|
|
|
135
135
|
use ${rustcrate}::utility::clean;
|
|
136
136
|
use ${rustcrate}::utility::voxgigstruct as vs;
|
|
137
137
|
use ${rustcrate}::{
|
|
138
|
-
Context, CtxSpec, Entity, Feature, FeatureRef, ${Name}
|
|
138
|
+
Context, CtxSpec, Entity, Feature, FeatureRef, ${Name}EntityBase, ${Name}Error, ${Name}SDK, Value,
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
// Generated: the credential's wire placement is fixed when the SDK is built.
|
|
@@ -184,7 +184,7 @@ use common::*;
|
|
|
184
184
|
|
|
185
185
|
use ${rustcrate}::core::helpers::{getp, getpath, ja, jo, now_ms, setp, to_map};
|
|
186
186
|
use ${rustcrate}::utility::voxgigstruct as vs;
|
|
187
|
-
use ${rustcrate}::{test_sdk, Entity, ${model.const.Name}
|
|
187
|
+
use ${rustcrate}::{test_sdk, Entity, ${model.const.Name}EntityBase, ${model.const.Name}SDK, Value};
|
|
188
188
|
|
|
189
189
|
${liveStrictNote(strict, '//')}
|
|
190
190
|
const LIVE_STRICT: bool = ${strict};
|
|
@@ -10,7 +10,7 @@ use crate::core::context::{Context, CtxSpec};
|
|
|
10
10
|
use crate::core::error::ProjectNameError;
|
|
11
11
|
use crate::core::helpers::{get_bool, getp, setp, to_map};
|
|
12
12
|
use crate::core::sdk::ProjectNameSDK;
|
|
13
|
-
use crate::core::types::{Entity,
|
|
13
|
+
use crate::core::types::{Entity, ProjectNameEntityBase};
|
|
14
14
|
use crate::core::utility_type::Utility;
|
|
15
15
|
use crate::utility::voxgigstruct as vs;
|
|
16
16
|
use crate::utility::voxgigstruct::Value;
|
|
@@ -302,7 +302,7 @@ impl Entity for EntyClass {
|
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
impl
|
|
305
|
+
impl ProjectNameEntityBase for EntyClass {
|
|
306
306
|
// #LoadOp
|
|
307
307
|
|
|
308
308
|
// #ListOp
|
|
@@ -333,7 +333,7 @@ voxgig_value* utility_fetch(Utility* u, Context* ctx, const char* url,
|
|
|
333
333
|
voxgig_value* fetchdef, PNError** err);
|
|
334
334
|
|
|
335
335
|
// ===========================================================================
|
|
336
|
-
// Entity (vtable; mirrors core/types.rs Entity +
|
|
336
|
+
// Entity (vtable; mirrors core/types.rs Entity + ProjectNameEntityBase)
|
|
337
337
|
// ===========================================================================
|
|
338
338
|
|
|
339
339
|
// Every operation resolves to the ENTITY, not the raw data. `list` resolves
|
|
@@ -356,7 +356,7 @@ typedef struct EntityVT {
|
|
|
356
356
|
void (*mark_deleted)(Entity*);
|
|
357
357
|
bool (*deleted)(Entity*);
|
|
358
358
|
|
|
359
|
-
// CRUD ops (
|
|
359
|
+
// CRUD ops (ProjectNameEntityBase). On error set *err and return NULL.
|
|
360
360
|
Entity* (*load)(Entity*, voxgig_value* reqmatch, voxgig_value* ctrl, PNError** err);
|
|
361
361
|
// Returns a NULL-terminated Entity* array (never NULL on success).
|
|
362
362
|
Entity** (*list)(Entity*, voxgig_value* reqmatch, voxgig_value* ctrl, PNError** err);
|
|
@@ -6,7 +6,7 @@ import (
|
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
// UnsupportedOp is returned by entity stub methods for operations the
|
|
9
|
-
// underlying API spec doesn't define. The static
|
|
9
|
+
// underlying API spec doesn't define. The static ProjectNameEntityBase interface
|
|
10
10
|
// requires every CRUD method on every entity, so absent ops must still be
|
|
11
11
|
// callable — they error at runtime instead of failing to compile.
|
|
12
12
|
func UnsupportedOp(opname, entityname string) (any, error) {
|
|
@@ -33,7 +33,10 @@ type Entity interface {
|
|
|
33
33
|
Deleted() bool
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// ProjectNameEntityBase is the full CRUD contract every generated entity
|
|
37
|
+
// implements. Named `...Base`, as in the other targets, because an entity
|
|
38
|
+
// struct is `<Entity>Entity`.
|
|
39
|
+
type ProjectNameEntityBase interface {
|
|
37
40
|
Entity
|
|
38
41
|
Load(reqmatch map[string]any, ctrl map[string]any) (any, error)
|
|
39
42
|
List(reqmatch map[string]any, ctrl map[string]any) (any, error)
|
|
@@ -52,3 +55,8 @@ type StreamItem struct {
|
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
type FetcherFunc func(ctx *Context, fullurl string, fetchdef map[string]any) (any, error)
|
|
58
|
+
|
|
59
|
+
// ProjectNameEntity is the former name of ProjectNameEntityBase.
|
|
60
|
+
//
|
|
61
|
+
// Deprecated: use ProjectNameEntityBase.
|
|
62
|
+
type ProjectNameEntity = ProjectNameEntityBase
|
|
@@ -13,7 +13,7 @@ use crate::utility::voxgigstruct::major::Injection;
|
|
|
13
13
|
use vs::Value;
|
|
14
14
|
|
|
15
15
|
// UnsupportedOp is returned by entity stub methods for operations the
|
|
16
|
-
// underlying API spec doesn't define. The static
|
|
16
|
+
// underlying API spec doesn't define. The static ProjectNameEntityBase trait
|
|
17
17
|
// requires every CRUD method on every entity, so absent ops must still be
|
|
18
18
|
// callable — they error at runtime instead of failing to compile.
|
|
19
19
|
pub fn unsupported_op(opname: &str, entityname: &str) -> ProjectNameError {
|
|
@@ -76,9 +76,9 @@ pub trait Entity {
|
|
|
76
76
|
fn deleted(&self) -> bool;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
///
|
|
79
|
+
/// ProjectNameEntityBase: the full CRUD contract every generated entity
|
|
80
80
|
/// implements. Ops the API spec doesn't define are runtime-error stubs.
|
|
81
|
-
pub trait
|
|
81
|
+
pub trait ProjectNameEntityBase: Entity + Sized {
|
|
82
82
|
fn load(self: &Rc<Self>, reqmatch: Value, ctrl: Value) -> Result<Rc<Self>, ProjectNameError>;
|
|
83
83
|
fn list(self: &Rc<Self>, reqmatch: Value, ctrl: Value) -> Result<Vec<Rc<Self>>, ProjectNameError>;
|
|
84
84
|
fn create(self: &Rc<Self>, reqdata: Value, ctrl: Value) -> Result<Rc<Self>, ProjectNameError>;
|