Skip to content

Commit a85d864

Browse files
committed
fixed toolkit tutorial
1 parent a4ed565 commit a85d864

File tree

7 files changed

+378
-200
lines changed

7 files changed

+378
-200
lines changed

docs/client/2-client-engine-RsHiqhe6.js

Lines changed: 64 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/client/3-database-engine-zkbqPJ6r.js

Lines changed: 77 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/client/4-context-provider-1103qu6e.js

Lines changed: 77 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/toolkit/setup/2-client-engine.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

plugins/docs/views/toolkit/setup/2-client-engine.tsx

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ const examples = [
3030
import type { Config } from 'stackpress/types';
3131
import unocss from 'unocss/vite';
3232
33+
const cwd = process.cwd();
34+
const build = path.join(cwd, '.build');
35+
3336
export const config: Config = {
3437
//...
3538
database: {
@@ -38,13 +41,20 @@ export const config: Config = {
3841
//where to store create and alter table migration files
3942
// - This is used in conjunction with \`revisions\`
4043
// - This doesn't update the database, it simply logs the changes
41-
migrations: path.join(build, 'migrations'),
42-
//cascading rules used when generating the database schema
43-
//options: 'CASCADE', 'SET NULL', 'RESTRICT'
44-
schema: {
45-
onDelete: 'CASCADE' as Cascade,
46-
onUpdate: 'RESTRICT' as Cascade
47-
}
44+
migrations: path.join(build, 'migrations')
45+
},
46+
client: {
47+
//used by stackpress/client to import()
48+
//the generated client code to memory
49+
module: 'stackpress-client',
50+
//name of the client package used in package.json
51+
package: 'stackpress-client',
52+
//where to store serialized idea json files for historical
53+
//purposes. Revisions are used in conjuction with push and
54+
//migrate to determine the changes between each idea change.
55+
revisions: path.join(build, 'revisions'),
56+
//what tsconfig file to base the typescript compiler on
57+
tsconfig: path.join(cwd, 'tsconfig.json')
4858
}
4959
};`,
5060
//1-------------------------------------------------------------------//
@@ -60,6 +70,10 @@ const content = {
6070
'config/develop.ts': `
6171
import type { Config } from 'stackpress/types';
6272
import unocss from 'unocss/vite';
73+
74+
const cwd = process.cwd();
75+
const build = path.join(cwd, '.build');
76+
6377
//development configuration
6478
const config: Config = {
6579
server: {
@@ -86,13 +100,20 @@ const config: Config = {
86100
//where to store create and alter table migration files
87101
// - This is used in conjunction with \`revisions\`
88102
// - This doesn't update the database, it simply logs the changes
89-
migrations: path.join(build, 'migrations'),
90-
//cascading rules used when generating the database schema
91-
//options: 'CASCADE', 'SET NULL', 'RESTRICT'
92-
schema: {
93-
onDelete: 'CASCADE' as Cascade,
94-
onUpdate: 'RESTRICT' as Cascade
95-
}
103+
migrations: path.join(build, 'migrations')
104+
},
105+
client: {
106+
//used by stackpress/client to import()
107+
//the generated client code to memory
108+
module: 'stackpress-client',
109+
//name of the client package used in package.json
110+
package: 'stackpress-client',
111+
//where to store serialized idea json files for historical
112+
//purposes. Revisions are used in conjuction with push and
113+
//migrate to determine the changes between each idea change.
114+
revisions: path.join(build, 'revisions'),
115+
//what tsconfig file to base the typescript compiler on
116+
tsconfig: path.join(cwd, 'tsconfig.json')
96117
}
97118
};
98119
//export configuration
@@ -527,12 +548,12 @@ export function Body() {
527548
{/*------------------------------------------------------------*/}
528549

529550
<a id="configure-database"></a>
530-
<H2>2.1. Configure Database</H2>
551+
<H2>2.2. Configure Database</H2>
531552

532553
<section>
533554
<P>
534555
Update the <H>config/develop.ts</H> file to include the
535-
following <C>database</C> configuration.
556+
following <C>database</C> and <C>client</C> configuration.
536557
</P>
537558

538559
<Code>{examples[1]}</Code>
@@ -574,6 +595,55 @@ export function Body() {
574595
</Table>
575596
</div>
576597

598+
<section>
599+
<P>
600+
The following explains the <C>client</C> configuration
601+
options.
602+
</P>
603+
</section>
604+
605+
<div className="px-w-100-0 overflow-x-auto">
606+
<Table>
607+
<Thead className="theme-bg-bg2 text-left">Options</Thead>
608+
<Thead wrap3 className="theme-bg-bg2 text-left">Notes</Thead>
609+
<Trow>
610+
<Tcol noWrap className="text-left">
611+
<C>{'module'}</C>
612+
</Tcol>
613+
<Tcol className="text-left">
614+
The name of the module that Stackpress will use to import the client
615+
</Tcol>
616+
</Trow>
617+
<Trow>
618+
<Tcol noWrap className="theme-bg-bg1 text-left">
619+
<C>{'package'}</C>
620+
</Tcol>
621+
<Tcol className="theme-bg-bg1 text-left">
622+
The name of the client package that will be used when
623+
generating a <C>package.json</C> during build
624+
</Tcol>
625+
</Trow>
626+
<Trow>
627+
<Tcol noWrap className="text-left">
628+
<C>{'revisions'}</C>
629+
</Tcol>
630+
<Tcol className="text-left">
631+
Where to store serialized idea json files for historical
632+
purposes. Revisions are used in conjuction with push and
633+
migrate to determine the changes between each idea change.
634+
</Tcol>
635+
</Trow>
636+
<Trow>
637+
<Tcol noWrap className="text-left">
638+
<C>{'tsconfig'}</C>
639+
</Tcol>
640+
<Tcol className="text-left">
641+
What tsconfig file to base the typescript compiler on
642+
</Tcol>
643+
</Trow>
644+
</Table>
645+
</div>
646+
577647
{/*------------------------------------------------------------*/}
578648

579649
<a id="create-idea-file"></a>
@@ -613,7 +683,7 @@ export function Body() {
613683
<H2>2.4. Generate Idea</H2>
614684

615685
<section>
616-
<P>In Terminal, run <C>npx stackpress config/develop generate</C>.</P>
686+
<P>In Terminal, run <C>npx stackpress generate --b config/develop</C>.</P>
617687

618688
<P>
619689
If you open the <H>node_modules</H> folder in the project root,

plugins/docs/views/toolkit/setup/3-database-engine.tsx

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,25 @@ export default function plugin(server: Server) {
6161
};`,
6262
//3-------------------------------------------------------------------//
6363
`//plugins/store/populate.ts
64-
import type { ProfileAuth } from 'stackpress';
64+
import type { Profile } from 'stackpress';
6565
import { action } from 'stackpress/server';
6666
6767
export default action(async function Populate(_req, _res, ctx) {
68-
const admin = await ctx.resolve<ProfileAuth>('auth-signup', {
68+
const profile = await ctx.resolve<Profile>('profile-create', {
6969
type: 'person',
7070
name: 'Admin',
71-
username: 'admin',
72-
email: 'admin@project.com',
73-
secret: 'admin',
7471
roles: [ 'ADMIN' ]
7572
});
73+
await ctx.resolve('auth-create', {
74+
profileId: profile.results?.id,
75+
type: 'username',
76+
token: 'admin',
77+
secret: 'admin'
78+
});
7679
await ctx.resolve('application-create', {
77-
profileId: admin.results?.id,
80+
profileId: profile.results?.id,
7881
name: 'Example App',
79-
scopes: [ 'user' ],
82+
scopes: [ 'profile-write', 'auth-read' ],
8083
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)
8184
});
8285
});`,
@@ -102,6 +105,10 @@ const content = {
102105
'config/develop.ts': `
103106
import type { Config } from 'stackpress/types';
104107
import unocss from 'unocss/vite';
108+
109+
const cwd = process.cwd();
110+
const build = path.join(cwd, '.build');
111+
105112
//development configuration
106113
const config: Config = {
107114
server: {
@@ -128,13 +135,20 @@ const config: Config = {
128135
//where to store create and alter table migration files
129136
// - This is used in conjunction with \`revisions\`
130137
// - This doesn't update the database, it simply logs the changes
131-
migrations: path.join(build, 'migrations'),
132-
//cascading rules used when generating the database schema
133-
//options: 'CASCADE', 'SET NULL', 'RESTRICT'
134-
schema: {
135-
onDelete: 'CASCADE' as Cascade,
136-
onUpdate: 'RESTRICT' as Cascade
137-
}
138+
migrations: path.join(build, 'migrations')
139+
},
140+
client: {
141+
//used by stackpress/client to import()
142+
//the generated client code to memory
143+
module: 'stackpress-client',
144+
//name of the client package used in package.json
145+
package: 'stackpress-client',
146+
//where to store serialized idea json files for historical
147+
//purposes. Revisions are used in conjuction with push and
148+
//migrate to determine the changes between each idea change.
149+
revisions: path.join(build, 'revisions'),
150+
//what tsconfig file to base the typescript compiler on
151+
tsconfig: path.join(cwd, 'tsconfig.json')
138152
}
139153
};
140154
//export configuration
@@ -239,20 +253,23 @@ export default function plugin(server: Server) {
239253
`.trim(),
240254
//3-------------------------------------------------------------------//
241255
'plugins/store/populate.ts': `
242-
import type { ProfileAuth } from 'stackpress';
256+
import type { Profile } from 'stackpress';
243257
import { action } from 'stackpress/server';
244258
245259
export default action(async function Populate(_req, _res, ctx) {
246-
const admin = await ctx.resolve<ProfileAuth>('auth-signup', {
260+
const profile = await ctx.resolve<Profile>('profile-create', {
247261
type: 'person',
248262
name: 'Admin',
249-
username: 'admin',
250-
email: 'admin@project.com',
251-
secret: 'admin',
252263
roles: [ 'ADMIN' ]
253264
});
265+
await ctx.resolve('auth-create', {
266+
profileId: profile.results?.id,
267+
type: 'username',
268+
token: 'admin',
269+
secret: 'admin'
270+
});
254271
await ctx.resolve('application-create', {
255-
profileId: admin.results?.id,
272+
profileId: profile.results?.id,
256273
name: 'Example App',
257274
scopes: [ 'profile-write', 'auth-read' ],
258275
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)
@@ -653,9 +670,9 @@ export function Body() {
653670
</P>
654671

655672
<ol className="px-px-10 px-lh-30 px-py-20">
656-
<li>1. In Terminal, run <B>npx stackpress config/develop generate</B></li>
657-
<li>2. In Terminal, run <B>npx stackpress config/develop push</B></li>
658-
<li>3. In Terminal, run <B>npx stackpress config/develop emit populate</B></li>
673+
<li>1. In Terminal, run <B>npx stackpress generate --b config/develop</B></li>
674+
<li>2. In Terminal, run <B>npx stackpress push --b config/develop</B></li>
675+
<li>3. In Terminal, run <B>npx stackpress emit populate --b config/develop</B></li>
659676
</ol>
660677

661678
<Note>
@@ -681,7 +698,7 @@ export function Body() {
681698
<Thead className="theme-bg-bg2 text-left">Notes</Thead>
682699
<Trow>
683700
<Tcol noWrap className="text-left">
684-
<B>npx stackpress config/develop migrate</B>
701+
<B>npx stackpress migrate --b config/develop</B>
685702
</Tcol>
686703
<Tcol className="text-left">
687704
Creates a <H>migrations</H> folder
@@ -691,27 +708,27 @@ export function Body() {
691708
</Trow>
692709
<Trow>
693710
<Tcol noWrap className="theme-bg-bg1 text-left">
694-
<B>npx stackpress config/develop purge</B>
711+
<B>npx stackpress purge --b config/develop</B>
695712
</Tcol>
696713
<Tcol className="theme-bg-bg1 text-left">
697714
Removes all rows from all tables in the database.
698715
</Tcol>
699716
</Trow>
700717
<Trow>
701718
<Tcol noWrap className="text-left">
702-
<B>npx stackpress config/develop push</B>
719+
<B>npx stackpress push --b config/develop</B>
703720
</Tcol>
704721
<Tcol className="text-left">
705722
Pushes schema changes to the database.
706723
</Tcol>
707724
</Trow>
708725
<Trow>
709726
<Tcol noWrap className="theme-bg-bg1 text-left">
710-
<B>npx stackpress config/develop query</B>
727+
<B>npx stackpress query</B>
711728
</Tcol>
712729
<Tcol className="theme-bg-bg1 text-left">
713730
Queries the database. ie.
714-
<C>{`npx stackpress config/develop query "SELECT * FROM users"`}</C>
731+
<C>{`npx stackpress query "SELECT * FROM users"`}</C>
715732
</Tcol>
716733
</Trow>
717734
</Table>

plugins/docs/views/toolkit/setup/4-context-provider.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ const content = {
6868
'config/develop.ts': `
6969
import type { Config } from 'stackpress/types';
7070
import unocss from 'unocss/vite';
71+
72+
const cwd = process.cwd();
73+
const build = path.join(cwd, '.build');
74+
7175
//development configuration
7276
const config: Config = {
7377
server: {
@@ -94,13 +98,20 @@ const config: Config = {
9498
//where to store create and alter table migration files
9599
// - This is used in conjunction with \`revisions\`
96100
// - This doesn't update the database, it simply logs the changes
97-
migrations: path.join(build, 'migrations'),
98-
//cascading rules used when generating the database schema
99-
//options: 'CASCADE', 'SET NULL', 'RESTRICT'
100-
schema: {
101-
onDelete: 'CASCADE' as Cascade,
102-
onUpdate: 'RESTRICT' as Cascade
103-
}
101+
migrations: path.join(build, 'migrations')
102+
},
103+
client: {
104+
//used by stackpress/client to import()
105+
//the generated client code to memory
106+
module: 'stackpress-client',
107+
//name of the client package used in package.json
108+
package: 'stackpress-client',
109+
//where to store serialized idea json files for historical
110+
//purposes. Revisions are used in conjuction with push and
111+
//migrate to determine the changes between each idea change.
112+
revisions: path.join(build, 'revisions'),
113+
//what tsconfig file to base the typescript compiler on
114+
tsconfig: path.join(cwd, 'tsconfig.json')
104115
}
105116
};
106117
//export configuration
@@ -230,20 +241,23 @@ export default function plugin(server: Server) {
230241
`.trim(),
231242
//3-------------------------------------------------------------------//
232243
'plugins/store/populate.ts': `
233-
import type { ProfileAuth } from 'stackpress';
244+
import type { Profile } from 'stackpress';
234245
import { action } from 'stackpress/server';
235246
236247
export default action(async function Populate(_req, _res, ctx) {
237-
const admin = await ctx.resolve<ProfileAuth>('auth-signup', {
248+
const profile = await ctx.resolve<Profile>('profile-create', {
238249
type: 'person',
239250
name: 'Admin',
240-
username: 'admin',
241-
email: 'admin@project.com',
242-
secret: 'admin',
243251
roles: [ 'ADMIN' ]
244252
});
253+
await ctx.resolve('auth-create', {
254+
profileId: profile.results?.id,
255+
type: 'username',
256+
token: 'admin',
257+
secret: 'admin'
258+
});
245259
await ctx.resolve('application-create', {
246-
profileId: admin.results?.id,
260+
profileId: profile.results?.id,
247261
name: 'Example App',
248262
scopes: [ 'profile-write', 'auth-read' ],
249263
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365)

0 commit comments

Comments
 (0)