pinstripe 0.9.0 → 0.12.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.
Files changed (131) hide show
  1. package/README.md +1 -1
  2. package/cli.js +5 -7
  3. package/lib/async_path_builder.js +4 -0
  4. package/lib/async_path_builder.test.js +11 -0
  5. package/lib/base.js +13 -2
  6. package/lib/base.test.js +30 -28
  7. package/lib/client.js +49 -0
  8. package/lib/command.js +20 -0
  9. package/lib/commands/_importer.js +2 -0
  10. package/lib/commands/create_database.js +1 -3
  11. package/lib/commands/drop_database.js +1 -3
  12. package/lib/commands/generate_command.js +10 -8
  13. package/lib/commands/generate_migration.js +10 -8
  14. package/lib/commands/generate_model.js +11 -9
  15. package/lib/commands/generate_node_wrapper.js +36 -0
  16. package/lib/commands/generate_project.js +2 -11
  17. package/lib/commands/generate_service.js +10 -8
  18. package/lib/commands/generate_static_site.js +79 -0
  19. package/lib/commands/generate_view.js +6 -8
  20. package/lib/commands/init_database.js +2 -4
  21. package/lib/commands/list_commands.js +2 -3
  22. package/lib/commands/list_migrations.js +2 -3
  23. package/lib/commands/list_models.js +2 -3
  24. package/lib/commands/list_node_wrappers.js +14 -0
  25. package/lib/commands/list_services.js +2 -3
  26. package/lib/commands/list_views.js +2 -3
  27. package/lib/commands/migrate_database.js +1 -3
  28. package/lib/commands/reset_database.js +2 -4
  29. package/lib/commands/seed_database.js +2 -4
  30. package/lib/commands/start_console.js +2 -3
  31. package/lib/commands/start_server.js +17 -10
  32. package/lib/constants.js +0 -9
  33. package/lib/css.js +101 -0
  34. package/lib/database/adapter.js +23 -0
  35. package/lib/database/adapters/mysql.js +629 -0
  36. package/lib/database/adapters/sqlite.js +590 -0
  37. package/lib/database/column.js +8 -48
  38. package/lib/database/constants.js +25 -44
  39. package/lib/database/migration.js +20 -0
  40. package/lib/database/migrator.js +6 -3
  41. package/lib/database/row.js +152 -96
  42. package/lib/database/sql.js +47 -44
  43. package/lib/database/sql.test.js +58 -0
  44. package/lib/database/table.js +77 -202
  45. package/lib/database/union.js +21 -39
  46. package/lib/database.js +30 -121
  47. package/lib/environment.js +4 -2
  48. package/lib/html.js +1 -1
  49. package/lib/import_all.js +22 -9
  50. package/lib/index.js +7 -8
  51. package/lib/initialize.client.js +3 -3
  52. package/lib/migrations/1627976184_create_user.js +2 -4
  53. package/lib/migrations/1628057822_create_session.js +2 -4
  54. package/lib/migrations/_importer.js +2 -0
  55. package/lib/models/_importer.js +2 -0
  56. package/lib/models/session.js +2 -4
  57. package/lib/models/user.js +4 -5
  58. package/lib/node_wrapper.js +242 -26
  59. package/lib/node_wrappers/_importer.js +2 -0
  60. package/lib/node_wrappers/anchor.client.js +18 -0
  61. package/lib/{widgets → node_wrappers}/document.client.js +12 -19
  62. package/lib/node_wrappers/form.client.js +16 -0
  63. package/lib/{widgets → node_wrappers}/frame.client.js +32 -11
  64. package/lib/node_wrappers/helpers.js +48 -0
  65. package/lib/node_wrappers/markdown_editor/line_inserter.client.js +14 -0
  66. package/lib/node_wrappers/markdown_editor.client.js +34 -0
  67. package/lib/node_wrappers/overlay.client.js +26 -0
  68. package/lib/{widgets/document → node_wrappers}/progress_bar.client.js +7 -6
  69. package/lib/overload.js +1 -0
  70. package/lib/service_factory.js +40 -0
  71. package/lib/services/_importer.js +2 -0
  72. package/lib/services/args.js +1 -4
  73. package/lib/services/cli_utils.js +2 -4
  74. package/lib/services/config.js +19 -8
  75. package/lib/services/cookies.js +2 -4
  76. package/lib/services/database.js +2 -5
  77. package/lib/services/fetch.js +33 -23
  78. package/lib/services/fork_environment.js +2 -4
  79. package/lib/services/fs_builder.js +2 -3
  80. package/lib/services/params.js +1 -4
  81. package/lib/services/project.js +1 -3
  82. package/lib/services/read_file.js +6 -0
  83. package/lib/services/render_css.js +6 -0
  84. package/lib/services/render_file.js +4 -7
  85. package/lib/services/render_form.js +108 -66
  86. package/lib/services/render_html.js +2 -4
  87. package/lib/services/render_list.js +58 -0
  88. package/lib/services/render_markdown.js +44 -0
  89. package/lib/services/render_table.js +67 -0
  90. package/lib/services/render_view.js +7 -18
  91. package/lib/services/reset_environment.js +2 -4
  92. package/lib/services/run_command.js +2 -4
  93. package/lib/services/session.js +2 -4
  94. package/lib/services/theme_config.js +76 -0
  95. package/lib/services/view.js +4 -0
  96. package/lib/thatify.js +1 -1
  97. package/lib/url.js +12 -4
  98. package/lib/url.test.js +5 -1
  99. package/lib/validatable.js +1 -5
  100. package/lib/view.js +109 -2
  101. package/lib/views/_importer.js +2 -0
  102. package/lib/views/{layout.js → _layout.js} +13 -17
  103. package/lib/views/base.css.js +657 -0
  104. package/lib/views/blocks/default.js +25 -0
  105. package/lib/views/blocks/help.js +139 -0
  106. package/lib/views/bundle.js.js +36 -0
  107. package/lib/{controllers → views}/sign_in.js +5 -4
  108. package/lib/views/sign_out.js +15 -0
  109. package/lib/virtual_node.js +41 -46
  110. package/package.json +10 -14
  111. package/babel.config.cjs +0 -12
  112. package/lib/commands/generate_controller.js +0 -33
  113. package/lib/commands/generate_widget.js +0 -30
  114. package/lib/commands/list_controllers.js +0 -15
  115. package/lib/commands/list_widgets.js +0 -15
  116. package/lib/controller.js +0 -19
  117. package/lib/controllers/bundle.js +0 -62
  118. package/lib/controllers/sign_out.js +0 -15
  119. package/lib/renderable.js +0 -25
  120. package/lib/scss/index.scss +0 -2
  121. package/lib/services/render_controller.js +0 -11
  122. package/lib/services/render_script.js +0 -14
  123. package/lib/static/bundle.css +0 -10308
  124. package/lib/static/bundle.css.map +0 -1
  125. package/lib/widgets/anchor.client.js +0 -54
  126. package/lib/widgets/document/style.client.js +0 -49
  127. package/lib/widgets/form.client.js +0 -61
  128. package/lib/widgets/input.client.js +0 -23
  129. package/lib/widgets/overlay.client.js +0 -27
  130. package/lib/widgets/script.client.js +0 -9
  131. package/pinstripe.scss +0 -2
@@ -1,10 +1,9 @@
1
1
 
2
2
  import chalk from 'chalk';
3
- import { defineCommand } from 'pinstripe';
4
3
 
5
4
  import { Row } from '../database/row.js';
6
5
 
7
- defineCommand('list-models', () => {
6
+ export default () => {
8
7
  console.log('');
9
8
  console.log('The following models are available:');
10
9
  console.log('');
@@ -12,4 +11,4 @@ defineCommand('list-models', () => {
12
11
  console.log(` * ${chalk.green(modelName)}`);
13
12
  });
14
13
  console.log('');
15
- });
14
+ };
@@ -0,0 +1,14 @@
1
+
2
+ import chalk from 'chalk';
3
+
4
+ import { NodeWrapper } from '../node_wrapper.js';
5
+
6
+ export default () => {
7
+ console.log('');
8
+ console.log('The following node wrappers are available:');
9
+ console.log('');
10
+ Object.keys(NodeWrapper.classes).sort().forEach(nodeWrapperName => {
11
+ console.log(` * ${chalk.green(nodeWrapperName)}`);
12
+ });
13
+ console.log('');
14
+ };
@@ -1,10 +1,9 @@
1
1
 
2
2
  import chalk from 'chalk';
3
- import { defineCommand } from 'pinstripe';
4
3
 
5
4
  import { ServiceFactory } from '../service_factory.js';
6
5
 
7
- defineCommand('list-services', () => {
6
+ export default () => {
8
7
  console.log('');
9
8
  console.log('The following services are available:');
10
9
  console.log('');
@@ -12,5 +11,5 @@ defineCommand('list-services', () => {
12
11
  console.log(` * ${chalk.green(serviceName)}`);
13
12
  });
14
13
  console.log('');
15
- });
14
+ };
16
15
 
@@ -1,10 +1,9 @@
1
1
 
2
2
  import chalk from 'chalk';
3
- import { defineCommand } from 'pinstripe';
4
3
 
5
4
  import { View } from '../view.js';
6
5
 
7
- defineCommand('list-views', () => {
6
+ export default () => {
8
7
  console.log('');
9
8
  console.log('The following views are available:');
10
9
  console.log('');
@@ -12,4 +11,4 @@ defineCommand('list-views', () => {
12
11
  console.log(` * ${chalk.green(viewName)}`);
13
12
  });
14
13
  console.log('');
15
- });
14
+ };
@@ -1,4 +1,2 @@
1
1
 
2
- import { defineCommand } from 'pinstripe';
3
-
4
- defineCommand('migrate-database', ({ database }) => database.migrate());
2
+ export default ({ database }) => database.migrate();
@@ -1,7 +1,5 @@
1
1
 
2
- import { defineCommand } from 'pinstripe';
3
-
4
- defineCommand('reset-database', async ({ runCommand }) => {
2
+ export default async ({ runCommand }) => {
5
3
  await runCommand('drop-database');
6
4
  await runCommand('init-database');
7
- });
5
+ };
@@ -1,6 +1,4 @@
1
1
 
2
- import { defineCommand } from 'pinstripe';
3
-
4
- defineCommand('seed-database', () => {
2
+ export default () => {
5
3
  // do nothing
6
- });
4
+ };
@@ -2,11 +2,10 @@
2
2
  import * as Repl from 'repl';
3
3
  import * as vm from 'vm';
4
4
  import * as util from 'util';
5
- import { defineCommand } from 'pinstripe';
6
5
 
7
6
  import { ServiceFactory } from '../service_factory.js';
8
7
 
9
- defineCommand('start-console', async ({ environment, resetEnvironment }) => {
8
+ export default async ({ environment, resetEnvironment }) => {
10
9
  await new Promise(resolve => {
11
10
  const repl = Repl.start({
12
11
  prompt: 'pinstripe > ',
@@ -47,4 +46,4 @@ defineCommand('start-console', async ({ environment, resetEnvironment }) => {
47
46
  repl.on('exit', resolve);
48
47
  });
49
48
  await resetEnvironment();
50
- });
49
+ };
@@ -4,9 +4,7 @@ import Busboy from 'busboy';
4
4
  import { default as qs} from 'qs';
5
5
  const { parse: parseQueryString } = qs;
6
6
 
7
- import { defineCommand } from 'pinstripe';
8
-
9
- defineCommand('start-server', async ({ fetch }) => {
7
+ export default async ({ fetch }) => {
10
8
  const host = process.env.HOST || '127.0.0.1';
11
9
  const port = process.env.PORT || 3000;
12
10
 
@@ -22,14 +20,14 @@ defineCommand('start-server', async ({ fetch }) => {
22
20
  response.end();
23
21
  } catch (e){
24
22
  response.statusCode = 500;
25
- response.setHeader('Content-Type', 'text/plain');
23
+ response.setHeader('content-type', 'text/plain');
26
24
  response.end((e.stack || e).toString());
27
25
  }
28
26
  console.log(`${request.method}: ${request.url} (${response.statusCode})`);
29
27
  }).listen(port, host, () => {
30
28
  console.log(`Pinstripe running at http://${host}:${port}/`)
31
29
  });
32
- });
30
+ };
33
31
 
34
32
  const extractParams = async (request) => {
35
33
  const { method, url, headers } = request;
@@ -51,18 +49,27 @@ const parseBody = (request) => new Promise((resolve) => {
51
49
  const out = {};
52
50
  const busboy = new Busboy({ headers: request.headers });
53
51
 
54
- busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
55
- const buffer = [];
56
- file.on('data', data => {
57
- buffer.push(data);
52
+ busboy.on('file', function(fieldname, file, filename, encoding, mimeType) {
53
+ const chunks = [];
54
+
55
+ file.on('data', chunk => {
56
+ chunks.push(Buffer.from(chunk));
58
57
  });
58
+
59
59
  file.on('end', () => {
60
- out[fieldname] = buffer.join('');
60
+ out[fieldname] = {
61
+ filename,
62
+ encoding,
63
+ mimeType,
64
+ data: Buffer.concat(chunks)
65
+ };
61
66
  });
62
67
  });
68
+
63
69
  busboy.on('field', (fieldname, value) => {
64
70
  out[fieldname] = value
65
71
  });
72
+
66
73
  busboy.on('finish', () => resolve(out));
67
74
 
68
75
  request.pipe(busboy);
package/lib/constants.js CHANGED
@@ -19,12 +19,3 @@ export const TEXT_ONLY_TAGS = [
19
19
  'script',
20
20
  'style'
21
21
  ];
22
-
23
- export const DEFAULT_WIDGETS = {
24
- a: 'anchor',
25
- form: 'form',
26
- input: 'input',
27
- textarea: 'input',
28
- script: 'script'
29
- };
30
-
package/lib/css.js ADDED
@@ -0,0 +1,101 @@
1
+
2
+ import { Base } from './base.js';
3
+
4
+ export const Css = Base.extend().include({
5
+
6
+ meta(){
7
+ this.assignProps({
8
+ render(...rules){
9
+ return this.new(compileRules(deepMerge({}, ...rules)));
10
+ }
11
+ });
12
+ },
13
+
14
+ initialize(value){
15
+ this.value = value;
16
+ },
17
+
18
+ toString(){
19
+ return this.value;
20
+ },
21
+
22
+ toResponseArray(status = 200, headers = {}){
23
+ return [status, {'content-type': 'text/css', ...headers}, [this.value.trim()]];
24
+ }
25
+ });
26
+
27
+ const compileRules = (rules, path = [], out = []) => {
28
+ const props = {};
29
+
30
+ Object.keys(rules).forEach(name => {
31
+ const value = rules[name];
32
+ if(typeof value == 'object') return;
33
+ props[name] = value;
34
+ });
35
+
36
+ if(path.length && Object.keys(props).length){
37
+ out.push(compileRule(path, props));
38
+ }
39
+
40
+ Object.keys(rules).forEach(name => {
41
+ const value = rules[name];
42
+ if(typeof value != 'object') return;
43
+ compileRules(value, [ ...path, name ], out);
44
+ });
45
+
46
+ if(!path.length) return out.join('\n');
47
+ };
48
+
49
+ const compileRule = (path, props) => {
50
+ const atRules = [];
51
+ let selector = '';
52
+ path.forEach((segment, i) => {
53
+ if(segment.match(/^@/)){
54
+ atRules.push(segment);
55
+ } else {
56
+ segment = segment.match(/&/) ? segment : `${i ? '& ' : '&'}${segment}`.replace(/,\s*/g, ', & ');
57
+ selector = selector.split(/,\s*/).map(selector => segment.replace(/&/g, selector)).join(', ');
58
+ }
59
+ });
60
+
61
+ const out = [];
62
+ const indent = [];
63
+
64
+ atRules.forEach(rule => {
65
+ out.push(`${indent.join('')}${rule} {`);
66
+ indent.push(' ');
67
+ });
68
+
69
+ out.push(`${indent.join('')}${selector} {`);
70
+ indent.push(' ');
71
+ Object.keys(props).forEach(name => {
72
+ const value = props[name];
73
+ out.push(`${indent.join('')}${normaliseName(name)}: ${name == 'content' ? `'${value}'` : value};`);
74
+ })
75
+ indent.pop();
76
+ out.push(`${indent.join('')}}`);
77
+
78
+ atRules.forEach(() => {
79
+ indent.pop();
80
+ out.push(`${indent.join('')}}`);
81
+ });
82
+
83
+ return out.join('\n');
84
+ };
85
+
86
+ const normaliseName = name => name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
87
+
88
+ const deepMerge = (destination = {}, ...sources) => {
89
+ sources.forEach(source => {
90
+ Object.keys(source).forEach(key => {
91
+ const value = source[key];
92
+ if(typeof value == 'object') {
93
+ destination[key] = deepMerge(typeof destination[key] == 'object' ? destination[key] : {}, value);
94
+ } else {
95
+ destination[key] = source[key];
96
+ }
97
+ });
98
+ });
99
+ return destination;
100
+ };
101
+
@@ -0,0 +1,23 @@
1
+
2
+ import { Base } from "../base.js";
3
+ import { Registrable } from '../registrable.js';
4
+
5
+ export const Adapter = Base.extend().include({
6
+ meta(){
7
+ this.include(Registrable);
8
+ },
9
+
10
+ initialize(config){
11
+ this.config = config;
12
+ }
13
+ });
14
+
15
+ export const createAdapterDeligator = namespace => name => {
16
+ return function(...args){
17
+ const { methods } = this._adapter;
18
+ if(methods && methods[namespace] && methods[namespace][name]){
19
+ return this._adapter.methods[namespace][name].call(this, ...args);
20
+ }
21
+ throw new Error(`Adapter method '${namespace}.${name}' does not exist.`)
22
+ }
23
+ };