Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ fields:
sender: int

### Information about the sender.
senderInfo: module:auth:UserInfoPublic?, api
senderInfo: module:auth:UserInfoPublic?, !persist

### True, if this message has been removed.
removed: bool

### The client message id, used to track if a message has been delivered.
clientMessageId: int?, api
clientMessageId: int?, !persist

### True if the message has been sent.
sent: bool?, api
sent: bool?, !persist

### List of attachments associated with this message.
attachments: List<ChatMessageAttachment>?
Expand Down
2 changes: 1 addition & 1 deletion packages/serverpod/lib/src/protocol/auth_key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fields:
hash: String

### The key sent to the server to authenticate.
key: String?, api
key: String?, !persist

### The scopes this key provides access to.
scopeNames: List<String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ class: ObjectFieldScopes
table: object_field_scopes
fields:
normal: String
api: String?, api
database: String?, database
api: String?, !persist
database: String?, scope=serverOnly
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ Iterable<Map<YamlScalar, YamlNode>> _extractKeyValuePairs(
void Function(String key, SourceSpan? span)? onNegatedKeyWithValue,
required DeepNestedNodeHandler handleDeepNestedNodes,
}) {
print('fieldOptions');
if (content == null) return [];

var fieldPairs = fieldOptions.map((stringifiedKeyValuePair) {
List<Map<YamlScalar, YamlNode>> fieldPairs = [];

for (var stringifiedKeyValuePair in fieldOptions) {
var keyValueSpan = _extractSubSpan(content, span, stringifiedKeyValuePair);

if (_hasNestedStringifiedValues(stringifiedKeyValuePair)) {
Expand All @@ -121,16 +124,18 @@ Iterable<Map<YamlScalar, YamlNode>> _extractKeyValuePairs(
var stringifiedContent = nestedComponents.last;

if (stringifiedContent == '') {
return _createdYamlScalarNode(
fieldPairs.add(_createdYamlScalarNode(
key,
null,
keyValueSpan,
);
));
continue;
} else {
var nestedSpan = _extractSubSpan(content, span, stringifiedContent);
var nodeMap = handleDeepNestedNodes(stringifiedContent, nestedSpan);

return _createYamlMapNode(key, nodeMap, keyValueSpan);
fieldPairs.add(_createYamlMapNode(key, nodeMap, keyValueSpan));
continue;
}
}

Expand All @@ -155,13 +160,15 @@ Iterable<Map<YamlScalar, YamlNode>> _extractKeyValuePairs(
}
}

return _createdYamlScalarNode(
fieldPairs.add(_createdYamlScalarNode(
key,
value,
keyValueSpan,
);
});
));
continue;
}

print(fieldPairs);
return fieldPairs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class ClassYamlDefinition {
),
ValidateNode(
Keyword.database,
isDeprecated: true,
alternativeUsageMessage: 'Use "scope=serverOnly" instead.',
valueRestriction: BooleanValueRestriction().validate,
mutuallyExclusiveKeys: {
Keyword.api,
Expand All @@ -98,6 +100,8 @@ class ClassYamlDefinition {
),
ValidateNode(
Keyword.api,
isDeprecated: true,
alternativeUsageMessage: 'Use "!persist" instead.',
valueRestriction: BooleanValueRestriction().validate,
mutuallyExclusiveKeys: {
Keyword.database,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:serverpod_cli/src/analyzer/entities/converter/converter.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';

main() {
test(' ', () {
var document = loadYamlDocument(
'''
field: String, !relation=value
''',
);

YamlMap node = document.contents as YamlMap;

var contentNode = node.nodes['field']!;
var content = contentNode.value;

var yamlMap = convertStringifiedNestedNodesToYamlMap(
content,
contentNode.span,
firstKey: 'type',
onDuplicateKey: (key, span) {
print('Duplicate key: $key');
},
onNegatedKeyWithValue: (key, span) {
print('Negated key with value: $key');
},
);
});


test(' ', () {
var document = loadYamlDocument(
'''
field: String, relation(!key=value, duplicated, duplicated)
''',
);

YamlMap node = document.contents as YamlMap;

var contentNode = node.nodes['field']!;
var content = contentNode.value;

var yamlMap = convertStringifiedNestedNodesToYamlMap(
content,
contentNode.span,
firstKey: 'type',
onDuplicateKey: (key, span) {
print('Duplicate key: $key');
},
onNegatedKeyWithValue: (key, span) {
print('Negated key with value: $key');
},
);
});
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:serverpod_cli/src/analyzer/code_analysis_collector.dart';
import 'package:serverpod_cli/src/analyzer/entities/definitions.dart';
import 'package:serverpod_cli/src/analyzer/entities/entity_analyzer.dart';
import 'package:serverpod_cli/src/generator/code_generation_collector.dart';
Expand Down Expand Up @@ -162,13 +163,29 @@ void main() {

expect(collector.errors.length, greaterThan(1));

var error1 = collector.errors[0];
var error2 = collector.errors[1];
var message1 = 'The "api" property is mutually exclusive with the '
'"database" property.';
var message2 = 'The "database" property is mutually exclusive with the '
'"api" property.';

expect(error1.message,
'The "database" property is mutually exclusive with the "api" property.');
expect(error2.message,
'The "api" property is mutually exclusive with the "database" property.');
var hasDatabaseError = collector.errors.any(
(error) => error.message == message1,
);

var hasApiError = collector.errors.any(
(error) => error.message == message2,
);

expect(
hasDatabaseError,
isTrue,
reason: 'Expected error message: $message1',
);
expect(
hasApiError,
isTrue,
reason: 'Expected error message: $message2',
);
},
);

Expand Down Expand Up @@ -198,6 +215,20 @@ void main() {
[definition],
);

test('then an error is reported', () {
expect(collector.errors, isNotEmpty);
});

test('then an deprecated error message is reported.', () {
var error = collector.errors.first as SourceSpanSeverityException;
expect(
error.message,
'The "database" property is deprecated. Use "scope=serverOnly" instead.',
);

expect(error.severity, SourceSpanSeverity.info);
}, skip: collector.errors.isEmpty);

test('then the generated entity has the serverOnly scope.', () {
expect(
definition.fields.last.scope,
Expand Down Expand Up @@ -233,6 +264,20 @@ void main() {
[definition],
);

test('then an error is reported', () {
expect(collector.errors, isNotEmpty);
});

test('then an deprecated error message is reported.', () {
var error = collector.errors.first as SourceSpanSeverityException;
expect(
error.message,
'The "api" property is deprecated. Use "!persist" instead.',
);

expect(error.severity, SourceSpanSeverity.info);
}, skip: collector.errors.isEmpty);

test('then the generated entity should not be persisted.', () {
expect(
definition.fields.last.shouldPersist,
Expand Down Expand Up @@ -336,10 +381,15 @@ void main() {
greaterThan(0),
reason: 'Expected an error, none was found.',
);
expect(
collector.errors.last.message,
'The "api" property is mutually exclusive with the "parent" property.',

var message =
'The "api" property is mutually exclusive with the "parent" property.';

var hasError = collector.errors.any(
(error) => error.message == message,
);

expect(hasError, isTrue, reason: 'Expected error message: $message');
},
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ fields:
class: Example
table: example
fields:
nameId: int, database,
nameId: int, !persist,

''',
Uri(path: 'lib/src/protocol/example.yaml'),
['lib', 'src', 'protocol'],
Expand Down Expand Up @@ -286,7 +287,7 @@ fields:
class: Example
table: example
fields:
nameId: Invalid-Type, database
nameId: Invalid-Type, !persist
''',
Uri(path: 'lib/src/protocol/example.yaml'),
['lib', 'src', 'protocol'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ indexes:

expect(collector.errors.length, greaterThan(0));

var error = collector.errors.first;
var error = collector.errors.last;

expect(
error.message,
Expand Down